Guido rethinking removal of cmp from sort method

Fons Adriaensen fons at linuxaudio.org
Mon Mar 28 18:36:36 EDT 2011


On Mon, Mar 28, 2011 at 11:06:20AM +0200, Antoon Pardon wrote:
 
> Asking for *real-world* uses is just how the python community smothers
> requests. 

It's quite a common strategy, I've seen it used in many
contexts. Which doesn't make it any more acceptable of
course.

> Should someone come with a use case, I expect the following
> to happenr: One will go over the case with magnifying glasses in
> search for any possible way in which it could be rewritten so as not
> to need the cmp anyway. This will probably not be a big problem because
> the person with the use case will probably have given a simplified example
> to explain the overal picture. However most people responding will
> ingnore the overal picture and focus on details that may very well work
> on the simplified example but may not in the specific real-world case.
> But since going over all details to argue the case will be too time
> consuming, in the end the person with the use case will simply fail to
> convince.

An accurate description of the process.

> Forcing people to use a key-function, will produce cases where python
> will ask for more memory and take longer to sort, than allowing to provide
> a cmp function. This for the simple reason that for some order-functions,
> the only way to write a key-function will be to write a specific class,
> that will implement the order with the same kind of code that otherwise
> would have been put in the cmp function, making the trade off: memory use
> vs speed no longer a trade off.

If cmp_to_key() would do some (probably impossible) magic - factoring
the user's cmp() into a non-trivial key mapping and a simpler and more
efficient compare - then it would make sense. But it doesn't do such
a thing. The 'key' it uses is just a copy, and the compare that will
be used finally is just the user's one. Nothing gained, just overhead
added.

> If the existance alone of such cases isn't enough to reverse the decision
> about the cmp-argument of the sort-method. My guess is that nothing will.

Sadly enough, that is probably a good guess.

Ciao,

-- 
FA




More information about the Python-list mailing list