Polymorphism without protocol dilution

Maurice Rabb m3rabb at stono.com
Mon Aug 31 17:34:18 UTC 1998


>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.

Good point.  I was so focused on other aspects of protocol dilution, didn't
consider the other form or dilution I was introducing.

at: key ifAbsentPutValueOf: aBlock
      self at: key ifAbsent: [ self at: key put: aBlock value ]

Perhaps this would be an even better name.


Though this wasn't the best example to illustrate it, sometime you still
want an variable to hold either anObject or aBlock that it can evaluate in
the same way.  If you want to prevent dilution, you shouldn't use #value.
However in this case IMHO I think that the name should be #asEvaluated.

BlockContext>>#asEvaluated
        ^self value

Object>>#asEvaluated
        ^self

(I still wish the convention for Blocks wasn't #value, and was instead
something like #evaluate.)

--Maurice

---------------------------------------------------------------------------
  Maurice Rabb    773.281.6003    Stono Technologies, LLC    Chicago, USA





More information about the Squeak-dev mailing list