[Python-ideas] a sorting protocol dunder method?
Rhodri James
rhodri at kynesim.co.uk
Mon Dec 4 14:51:16 EST 2017
On 04/12/17 18:01, brent bejot wrote:
> I'm +1 on this idea for the most part.
>
> I agree particularly with the idea that it is better OOP for an object to
> access it's member variables to create the key than an external container
> to do so.
This I'm absolutely fine with. Key methods are something to encourage.
The problem that I have is that once you get beyond simple lists of
number or strings, there often isn't a particularly obvious sort order,
or rather there are often multiple obvious sort orders and you may want
any of them. In fact I'd go so far as to suggest that there _usually_
isn't a single obvious sort order for non-trivial classes.
To take a non-Python example, I'm in charge of the reading rota at my
local church, and I keep a spreadsheet of readers to help me. Usually I
sort that list by the date people last read the lesson, so I can quickly
tell who I should ask next. When the newsletter asks me for a list of
readers, though, I sort them alphabetically by surname, which most
people would think of as the natural sorting order.
--
Rhodri James *-* Kynesim Ltd
More information about the Python-ideas
mailing list