On Mon, 31 Aug 1998 11:12:33 -0700, Travis Griggs wrote:
David N. Smith wrote:
I'd like to make a third kind of suggestion for your list. Don't mix blocks and other values. Make the protocol different. For example:
at: key ifAbsentPut: anObject self at: key ifAbsent: [ self at: key put: anObject ]
at: key ifAbsentPutValue: aBlock self at: key ifAbsent: [ self at: key put: aBlock value ]
Another effect of this suggestion is that it still allows putting blocks into dictionaries as values, while suggestions 1 and 2 do not.
Why don't we just add types to Smalltalk! Seriously people, that's what all of these messages are starting to look like. I can just see some of my methods in the future:
at: aKey ifAbsentPutValueOfOneArgBlockThatWontReturnNil: aBlock
Not that I necessarily have a better solution :). But it worries me when I see messages whose keyword parts are basically types. A little of this is OK, but I think it should be used sparingly.
Sorry, but in this case, types are not the answer. If types were appropriate I would expect the method to do the same thing but just handle the different types appropriately. However, in this case the block is being evaluated, not just being returned, i.e. the behavior is different.
Terry Raymond Crafted Smalltalk (401) 846-6573 http://www.craftedsmalltalk.com
squeak-dev@lists.squeakfoundation.org