Wednesday, November 24, 2010

TAG-SortFunctions Redux

The original TAG-SortFunctions received relatively positive feedback, thank you.

A couple things have happened between version 1 and the current version (4) that's in the Public Repository, based on feedback I received in various channels. One thing I haven't changed yet, is the method names #sortUp and #sortDown. It was proposed by one person that maybe these would better be called #ascending and #descending, so that code snippets read like
somePoints sort: #x ascending, #y descending
I'm torn. I think it reads better in context, but not as well in isolation. Which do you prefer better?

The things that have changed are:

  1. The Tests have been separated out into a separate package

  2. It was pointed out that you can't always count on a per element accessor being able to reduce to a collatable value. For example, what if you want to sort the names of customers, but based on a given collation algorithm.
    customers asSortedCollection: [:a :b | (UnicodeCollationAlgorithm collate: a with: b mode: #shifted) < 0]
    How would that dovetail with this approach? So I added support for two argument blocks. You can send sortUp/sortDown to them too. Under the hood now, the SortFunction is two argument collation block, and all roads lead to creating one of them.

  3. Because of that, you no longer need your flavor of Smalltalk to be able to do theSymbol value: trick.

  4. Since it all boils down to collation, I did add a new binary method: <=>. This is called the Spaceship operator in some language environments. So... you're Smalltalk flavor has to be able to support 3 character binary selectors for this to port.

  5. Despite seeming like a lot of changes, IIRC, the code actually ended up being smaller than the original.

1 comment:

  1. Hello Travis,

    Could you make this available to Squeak/Pharo users in some way?

    ReplyDelete