[ANSI-Smalltalk] Re: A list of interesting methods, ifNotNil:

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Sep 4 02:57:07 BST 2008


"Jim" ( jas at cruzio.com ) wrote that he preferred

isNil: a0block
notNil: a0block
nonNil: a1block
and various combinations of those to the by now traditional
[ifNil:][ifNotNil:]

As a Smalltalk user, it's quite important to me that methods
taking a block that might or might not be evaluated have
"if" in the keyword selector for that block.

For example, it's
    aCollection at: someKey ifAbsent: exceptionBlock
                            ^^
ifAbsent:, not isAbsent:, notPresent:, nonPresent:, or
anything else.

There seem to be three reasons for leaving [ifNil:][ifNotNil:]
out:
(1) No agreement about the optional argument in the not-nil
    block; of course the standard could cover just the no-
    argument case.
(2) These methods aren't really necessary unless you have
    redefined what nil == ... does.  A compiler can turn
	nil == (expr) ifTrue: b1 ifFalse: b2
    into whatever
        (expr) ifNil: b1 ifNotNil: b2
    does.
(3) Where do you stop?  Once you have these, why not
    b1 while[Not]Nil[: b2]?  Why not ifEmpty:ifNotEmpty:?
    This is actually a serious question; I've wanted
    b1 whileNotNil: b2 often enough.

On the other hand, the feature is widely available, and is
quite intention-revealing, so the answer to (3) is "because
these methods _are_ common practice and those aren't."
--
If stupidity were a crime, who'd 'scape hanging?










More information about the ANSI-Smalltalk mailing list