[ANSI-Smalltalk] Re: A list of interesting methods, ifNotNil:
John O'Keefe
wembley.instantiations at gmail.com
Mon Sep 8 13:40:03 BST 2008
VA Smalltalk also has some *Do: methods that do not imply iteration, but
they are few and relatively obscure (for the most part). I don't like them,
but I am forced to live with them. I am definitely against adding any more
selectors of their ilk -- either in our product or in the standard.
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
On Mon, Sep 8, 2008 at 7:26 AM, Paolo Bonzini <bonzini at gnu.org> wrote:
>
> > I am now confused.
> > The actual code in Squeak is
> >
> > ifNotEmptyDo: aBlock
> > ^self isEmpty ifTrue: [aBlock value: self]
> >
> > It certainly doesn't involve any sending of the message #do:.
>
> Which is all but intention revealing.
>
> > x isEmpty ifTrue: [x do: monadicBlock]
> >
> > would, if x is a collection, never do anything at all with monadicBlock.
> > I take it that this should have been
> >
> > x isEmpty ifFalse: [x do: monadicBlock]
> >
> > and there is a name for that too: #do:.
>
> Of course, but there is no existing name for #ifEmpty:ifNotEmptyDo:.
> Moreover, if you have another message #ifEmpty:ifNotEmpty: there is no
> hint that the two differ *in the arity of the second block*!
>
> If there were to be methods like #ifEmpty:, you should have only these
> four:
>
> #ifEmpty:
> #ifNotEmpty:
> #ifEmpty:ifNotEmpty:
> #ifNotEmpty:ifEmpty:
>
> plus possibly
>
> #ifEmpty:ifNotEmptyDo: (passing the second block to #do:)
> #ifNotEmptyDo:ifEmpty:
>
> Furthermore, all parameters of all six methods should have variable
> arity, because unlike the nil/not-nil case, there are many empty
> collections and you may want to know it even in the empty case. I agree
> that this is borderline -- I cannot think of a use case indeed, and most
> of the time you'll use #ifEmpty: just as a guard for ^self.
>
> > VisualWorks also has an if*Do: method or two.
> > GeneralBindingReference>>ifDefinedDo:
> > has nothing to do with #do:.
> > WindowManager>>activeControllerProcessIfBlockedDo:
> > also has nothing to do with #do:.
>
> But no #ifDefined: and #activeControllerProcessIfBlocked:. I don't like
> those names very much, but that's nothing compared to overloading "Do:"
> (which already has a well-known meaning in Smalltalk, i.e. "iterate") to
> mark arity.
>
> Paolo
>
>
>
> _______________________________________________
> ANSI-Smalltalk mailing list
> ANSI-Smalltalk at lists.openskills.org
> http://lists.openskills.org/cgi-bin/mailman/listinfo/ansi-smalltalk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openskills.org/pipermail/ansi-smalltalk/attachments/20080908/f52ca6ab/attachment.htm
More information about the ANSI-Smalltalk
mailing list