On Wed, 23 Dec 2009, Martin McClure wrote:
Levente Uzonyi wrote:
So the only use-case where SortedCollection is useful (IMO) is when you - have to keep the collection sorted and - you rarely some elements to it
Getting rid of other uses is hard because #asSortedCollection always returns a copy, while most #as* selectors don't.
I was slightly confused by this, but now think I see what you're saying.
Most #as* selectors return an instance of a different class, but answer self if the receiver is already of that class. But collections always answer a copy, even if it is already of that class.
All collections answer self, except instances of OrderedCollection SortedCollection and CharacterSet (at least in squeak).
Wondering why this was designed this way...
I think these methods (#asOrderedCollection #asSortedCollection #asCharacterSet) were added later than the others and those who added them didn't think about this implementation detail.
Perhaps it's the expected mutability of collections? When you send #asInteger, you don't care if you get the receiver back, because it's not mutable. But with a collection you almost always mutate it. In the
That's not true, LargeIntegers are mutable. I don't have numbers, but I think that most senders of #as* don't mutate the collection. Levente
case of #asString, Strings are mutable, but are not *commonly* mutated.
Regards,
-Martin
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project