[Newbies] How to empty a collection?

Randal L. Schwartz merlyn at stonehenge.com
Tue Feb 19 19:09:50 UTC 2008


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

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


More information about the Beginners mailing list