Does anyone else have this pattern?

J J azreal1977 at hotmail.com
Fri Jun 29 18:04:33 UTC 2007


I like this sort of pattern, but I wouldn't put it in the stock image.  I would make it an extension of whatever project uses it (i.e. it might be in Collection but under the protocol *Your-Project-Name), or maybe make a new project called "Collection extension" or something.> Date: Fri, 29 Jun 2007 15:56:26 +0100> From: pdcawley at bofh.org.uk> To: squeak-dev at lists.squeakfoundation.org> Subject: Does anyone else have this pattern?> > During my SmallLint directed exploration of the guts of the> OmniBrowser, I came across a chunk of code that looked (very> approximately like)> > coll := self buildCollection.> > coll ifEmpty: [^ self].> coll size = 1 ifTrue: [self browse: coll first].> self askUserToChooseFrom: coll.> > Now, call me Mr Fussy, but I really don't like seeing function scoped> temporaries if I can help it, so it seems to me that one could write a> method on Collection along the lines of:> > ifEmpty: emptyBlock ifSingular: singularBlock otherwise: otherwiseBlock> >     self ifEmpty [^ emptyBlock value].>     ^self size = 1>         ifTrue: [singularBlock valueWithPossibleArgument: self first]>         ifFalse: [otherwiseBlock valueWithPossibleArgument: self]> > Which would clean the original method up like so:> > self buildCollection>     ifEmpty: []>     ifSingular: [:node| self browse: node]>     otherwise: [:coll| self askUserToChooseFrom: col]> > Which, to my eyes at least, seems to express the intent more clearly.> > The obvious rearrangements and subsets spring to mind, along with> otherwiseDo:, otherwiseInject:, otherwiseCollect:> > So, am I alone in thinking something like this would be useful, and if> I'm not, what's the best way to go about getting it into the image?> Create a CollectionTesting package and add it to the dependencies of> any packages that use it? Submit a changeset somewhere? And enquiring> mind wants to know.> > Thanks in advance for your consideration.> 
_________________________________________________________________
Hotmail to go? Get your Hotmail, news, sports and much more! Check out the New MSN Mobile! 
http://mobile.msn.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070629/6fc6f026/attachment.htm


More information about the Squeak-dev mailing list