[BUG]Collection>>removeAll:

goran.hultgren at bluefish.se goran.hultgren at bluefish.se
Wed Aug 21 14:08:15 UTC 2002


Ralph Johnson <johnson at cs.uiuc.edu> wrote:
> To me, the definition of removeAll: is not an English description
> of what it does, it is
> 
> removeAll: aCollection
>   aCollection do: [:each | self remove: each]
> 
> The same for addAll:.  
> 
> Smalltalk might have been invented as a language for children,
> but that was a long time ago.  For the past 25 years or so, it
> has been a language for experienced programmers to build serious
> systems.
> 
> That said, if a lot of people make the same kind of mistake, it
> makes sense to change the system.  Collections should certainly
> support a removeAll operation that makes a collection empty.
> But the real problem here is that do: is not safe if the collection
> is being changed.  It would be pretty simple to change do: such that

Personally I think many proposed solutions are ok as long as it's not a
"programmer trap".

So one solution is to simply make sure the method comments don't trick
you or leave out something that has been shown to be important to know!

When it comes to using "x removeAll: x" as a substitute for #removeAll
then I am strongly in favour of instead introducing #removeAll. It more
precisely expresses what I want and it can thus be much more effectively
implemented. It's simply a matter of being semantically precise IMHO.

And finally, I agree that when people write "x removeAll: x" they should
be aware of that they are tempting fate, but do note that the code might
instead be something like:

x removeAll: <expression>

Where <expression> just happens to evaluate to x. Then it's not obvious
at all.

regards, Göran



More information about the Squeak-dev mailing list