[Newbies] How to empty a collection?

goran at krampe.se goran at krampe.se
Tue Feb 19 22:46:50 UTC 2008


merlyn at stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "goran" == goran  <goran at krampe.se> writes:
> >> I'd just do:
> >> 
> >> removeAll
> >> self notEmpty ifTrue: [self become: self species new].
> >> 
> >> and let subclasses make it more efficient using implementation knowledge.
> 
> goran> I would never use become: in "regular code" like this. :)
> 
> First, how "regular" is it if the method hasn't been missed by anyone
> in 27 years. :)
> 
> Second, what are you objecting to?  #become: is clearly a part of the image,
> and works fine.  This code also cleans out a grown collection to be the
> smallest it possiby can become, where delete-one-at-a-time solutions don't.
> 
> And, if there's a more efficient thing for subclasses, they can certainly
> override it.

Yes, I probably agree it would be a nice default implementation. Modulo
someone now telling us we missed something of course. :)

regards, Göran


More information about the Beginners mailing list