[Pharo-dev] about SortFunctions

Damien Pollet damien.pollet at gmail.com
Thu Nov 9 08:00:40 EST 2017


On 7 November 2017 at 14:48, Denis Kudriashov <dionisiydk at gmail.com> wrote:
>
> And we already have VM based String compare: with strange logic returning
>> 1, 2, 3. So we already can optimize current String>>threeWayCompareTo:.
>>
>
> Maybe good idea to open ticket and modify image level methods to return
> standard -1,0,1 values.
>

If we're modifying core sorting methods, we might as well use proper
objects instead of magic numbers…

Ordering
  Lesser
  Equal
  Greater
  (Unordered?)

And while I'm on the topic of vocabulary, I'm not convinced by
SortFunction… "to sort" means either to screen, to classify, or to arrange.
There is a notion of going through all elements and swapping them around or
putting in specific bins. Think QuickSort, MergeSort, etc

The mathematical term for the thing that determines whether two elements a
and b are such that a ≤ b is "Order relation". So IMHO Java's Comparator
fits the purpose much better; OrderFunction or OrderRelation would be nice
and just Order would have my preference:

Order with: aPredicate
(Order with: [:a :b | a < b]) value: 1 value 2. → the singleton instance of
Lesser

Order by: aMappingBlock
people sorted: (Order by: #name) , (Order by: #age)

Lesser >> #, innerOrder
  ^ self

Equal >> #, innerOrder
  ^ innerOrder

-- 
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20171109/e9feca1a/attachment-0002.html>


More information about the Pharo-dev mailing list