Guido rethinking removal of cmp from sort method

Carl Banks pavlovevidence at gmail.com
Wed Mar 23 21:40:44 EDT 2011


On Mar 23, 1:38 pm, Paul Rubin <no.em... at nospam.invalid> wrote:
> Carl Banks <pavlovevide... at gmail.com> writes:
> > It's kind of ridiculous to claim that cmp adds much complexity (it's
> > maybe ten lines of extra C code), so the only reason not to include it
> > is that it's much slower than using key.
>
> Well, I thought it was also to get rid of 3-way cmp in general, in favor
> of rich comparison.

Supporting both __cmp__ and rich comparison methods of a class does
add a lot of complexity.  The cmp argument of sort doesn't.

The cmp argument doesn't depend in any way on an object's __cmp__
method, so getting rid of __cmp__ wasn't any good readon to also get
rid of the cmp argument; their only relationship is that they're
spelled the same.  Nor is there any reason why cmp being a useful
argument of sort should indicate that __cmp__ should be retained in
classes.


Carl Banks



More information about the Python-list mailing list