[BUG]Collection>>removeAll:

David Griswold David.Griswold at acm.org
Mon Aug 19 20:32:03 UTC 2002


Maybe someone already pointed this out, but this whole discussion about
(x removeAll: x) is just a slippery slope that simply *can't* be solved
generally in an imperative language.  In any imperative language like
this, operations like removeAll: simply have as part of their contract
that the collections being operated on must remain invariant during some
period, and it is up to the caller to make sure that is true.  There are
a practically infinite variety of variations on this problem that you
could construct for almost anyplace in any library.  You can hack
specific cases, such as with removeAll:, but you can never eliminate
these sorts of things in general, and it is better to just educate
programmers about what the contract is.

As an example of the slippery slope, consider #do:.  People often try to
write code that mutates the collection while it is being iterated, which
is the same sort of problem as with removeAll:.  But trying to eliminate
all these problems will just slow the library down in increasingly
baroque and untenable ways, and lead programmers to believe that they
don't have to worry about these sorts of things, when in fact
programmers are going to think about these things anyway, in general,
unless they switch to a functional language ;-).

So the solution is: the library is fine; this is "operator error".
-Dave





More information about the Squeak-dev mailing list