[Newbies] Re: Recap: How to empty a collection

nicolas cellier ncellier at ifrance.com
Wed Feb 20 01:01:49 UTC 2008


Blake a écrit :
> On Tue, 19 Feb 2008 15:19:40 -0800, nicolas cellier 
> <ncellier at ifrance.com> wrote:
> 
>> But become: is still essential for operations like growing the 
>> MethodDictionary when you add new methods to a class, or migrate 
>> allInstances when you a or remove an instance variable to a class, to 
>> name few.
>> So, it is not bogus. Just handle with care.
> 

It seems that we are crossing all our posts!

> OK. Does a newbie need to use it? To empty a collection? (Or whatever?)
> 

Only an advanced newbie :) and in very rare case.
For squeak core library removeAll,
- pros: very generic
- cons: #become: is not efficient, especially in large images.
In fact, most #become: usages inherited from Smalltalk-80 have been 
removed from Squeak for this reason. It's wise not to reintroduce them.

> I'm trying to get at what should be a very simple thing without going to 
> the metal, as it were.
> 

Unfortunately, modifying a core library has such implications.

> One thing I wasn't clear on is whether Bert's suggestion:
> 
> aColl removeAllSuchThat: [:anElement| true].
> 
> Is okay, and why it's okay while many of the other similar approaches 
> were not.


Bert's suggestion is simple and works well.
The only question is about efficiency.
Up to (Down to?) subclasses to optimize it.

Some proposed an alternative based on (self removeAll: self), and 
started writing optimized versions of #removeAll:.

I think our biggest problem is that we have plenty possible ways to do 
it... Finding a balance between genericity and efficiency...

Nicolas



More information about the Beginners mailing list