Behavior methods

Eliot & Linda elcm at
Fri Jun 19 00:50:14 UTC 1998

Boris G. Chr. Shingarov wrote:
> sqrmax at wrote:
> > I've found faster implementations for four methods of Behaviour. Maybe
> > they're worth an update item. Two of the speedups are fourfold!
> The IBM implementation is almost as fast but is more elegant:
> Behavior>>allInstances
>    | aSet |
>    aSet := Set new.
>    self allSubclassesDo: [ :sub | aSet add: sub ].
>    ^aSet

But this implementation is totally incorrect.  It returns a Set of
objects that are not #= to each other, not an IdentitySet of objects
that are not #== to each other.  So if you use this to return all
instances it will frequently return a subset of all instances.

> Behavior>>allSubclassesDo: operation
>    "Evaluate the operation with the receiver's subclasses."
>    self subclasses do: [:sub |
>       operation value: sub.
>       sub allSubclassesDo: operation].
> (This is not exactly what is in IBM Smalltalk where allInstances
> returns an OrderedCollection, contrast to Set in Squeak.  I think
> it should be Set there - but maybe someone knows any specific
> reason for OC??)

Apart from Vasilli's reasons, one either needs to use an IdentitySet or
a sequence of some sort (e.g. an OrderedCollection or an Array, or even
a WeakArray) to ensure one is collecting each instance and not an
instance that represents a particular value.

Eliot Miranda, ParcPlace

More information about the Squeak-dev mailing list