The standard does *not* support - a removeAll: a - [was: Re: [BUG] Collection>>removeAll:]

Richard A. O'Keefe squeak-dev at lists.squeakfoundation.org
Tue Sep 3 03:14:14 UTC 2002


	This was, of course, my point.  Fixing a bug that might not be a bug to 
	introduce at least one bug that will certainly be a bug isn't the best 
	solution to this problem, particularly when the bug that might not be a 
	bug might not be a bug except in an obscure case where there isn't any 
	compelling need to fix the bug that might not be a bug.
	
Note that the code which is alleged to introduce a bug is not in fact
the code that is being proposed for inclusion in Squeak.  Goran has
persuasively argued that the "same object" case should call #removeAll,
which would NOT introduce a bug in this case.

    LinkedList "category 'removing'">>
    removeAll
        firstLink := lastLink := nil

The "oldElements copy do: [:each | self remove: each]" implementation
was used to make a point about interpreting the ANSI specification,
and that is all.  It is consistent with the ANSI specification, as
claimed, which means that it is possible and reasonable to interpret
the ANSI specification in a certain way.  No implementation could be
consistent with _every_ possible non-ANSI-conformant quasi-collection.

	Merely whining that a fundamental change to Collection is demanded 
	notwithstanding these problems because LinkedList isn't a "normal" 
	collection (which it isn't) is as silly as arguing that 
	ArraySliceCollection isn't yet a part of the core image.

Missing the point of an example is also "silly".

It would be very "silly" indeed to argue that ArraySliceCollection is not
part of the image, because it _is_.  It just happens to be called
MappedCollection.  However, just as programmers are expected to know
not to change a collection if they are iterating over it, they are expected
to know that they should not change a collection they have sliced,
except in code which explicitly takes the existence and range of the
slice into account.

To slice array a, do
    b := MappedCollection collection a: map: (first to: last).
It may not be _called_ a slice, but it's pretty much everything a slice
should be.  And it can slice an OrderedCollection or SortedCollection,
not just an Array.

MappedCollection has alreay been considered in this context.

By the way, nobody is arguing for a fundamental change to Collection.
Not for any specific fundamental change anyway.

	We shouldn't 
	do it in the absence of a comprehensive overhaul (including a 
	determination that same is needed) -- we are simply opening worms 
	everywhere to fix a maybe-a-bug that may or may not need fixing.
	
I am reminded of the man whose mother told him "No, you should not
get married yet, you are too young."  She kept on telling him that
until one day she told him "No, you should not get married, you are
too old."  I'm also reminded of "It's always jam TOMORROW, never jam
TODAY".  As soon as we poke _anywhere_ in Collection we find worms.
If we never dispose of the worms humanely, we'll have worms in the
heart of Squeak forever.

	Notwithstanding that, I am sensible to Richard's suggestion that when 
	it is practicable to catch a circumstance that misbehaves, we shouldn't 
	do so silently.  I am for adding the assert.
	
That would be something, at least.  Remember, it's addAll: too.



More information about the Squeak-dev mailing list