#sortBlock: is defined by ANSI on SortedCollection as an accessor and an instance creation method. That's what it sounds like and shouldn't be implemented on non-sorted collections.
Why? what would be the reason not to use sortBlock: for others? I like this consortium design that neglects basic polymorphism. May be in the future ANSI 1996 will look so old that we will be done with it.
#asSortedCollection is defined by ANSI on Collection and returns an instance of SortedCollection.
Yes it makes sense.
#sort and #sort: -- Squeak/Pharo have it on ArrayedCollection, VW has it on SequenceableCollection, and VASt will now add it. This sorts the instance in place.
I think that collection hierarchy shows the little of single inheritance and this is normal. Of course Interval is Sequenceable but I imagine cannot be sorted in place. Still some leaves like OrderedCollection could be really polymorphic. Now we would have it on OrderedCollection too and the subclasses of Sequenceable which make sense.
#sorted, #sorted: -- VW already has this. VA is adding it.
What is sorted? a boolean predicate method? What a bad name. Did they forgot Kent? I remember this cool period where moose stopped to work because sort was changed. They introduced that in VW and broke all our code by changing the sort: semantics. Now I checked and here is what I read SequenceableCollection>>sorted: aBlock "Return a sorted copy of the receiver using aBlock as the sort criteria. e.g. #(1 4 -5 -2 3) sorted: [:a :b | a abs <= b abs] returns a sorted copy of the receiver as #(1 -2 3 4 -5)" SequenceableCollection>>sorted "Return a sorted copy of the receiver." SequenceableCollection>>sort "Sort the receiver in place." Which clearly does not work on subclasses, of course. (1 to: -100 by: 3 ) sorted: [:a :b | a abs <= b abs] Why they did not use sortBlock: and sort: ? So we have conceptually sortInPlace: -> does not copy sort: -> does not do a copy as in pharo/squeak and VW and both could use sortBlock: (accessor and instance creation for SortedCollection) sort "Sort the receiver in place."
Squeak/Pharo should add it, IMO, but we'll add it to Grease if not. It returns a sorted copy of SequenceableCollections and a sorted Array of all other collections.
Please not this is bogus. It does not work with certain subclasses of Sequenceable And much more important it has a bad name. Because with a nice name sortCopy then it would be much better. So with one method in VW you can get it sortCopy ^ self sorted
#sortBy: is silly, as you mention and not supported on any other platform. We're adding it to our lint rules as a "do not use" method.
Yes. I would discard it.
We didn't notice #asSortedArray but I think that's a terrible name -- the pattern with #as* methods is that the thing after the "as" should be a class. That behaviour could be easily achieved with "aCollection sorted asArray" or "aCollection asArray sort" if really needed.
Yes we could probably remove them.
So that's what VASt/Seaside/Grease are doing... I encourage you to follow our lead. :)
:) yes but you can also avoid to propagate bad names in the community and sorted is a bad one. Because collections are not functional style as point in smalltalk so I have no clue to know if I get a new object or not.
Julian
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project