[Python-3000] Please re-add __cmp__ to python 3000
Guido van Rossum
guido at python.org
Tue Oct 16 22:27:22 CEST 2007
On 10/16/07, David A. Wheeler <dwheeler at dwheeler.com> wrote:
> I agree with Collin Winter: losing __cmp__ is a loss (see http://oakwinter.com/code/).
> Yes, it's possible to write all the comparison operations, but I think it's _clearer_ to create a single low-level operator that handles ALL the comparison operators. It also avoids many mistakes; once you get that ONE operator right, ALL comparisons are right. I think the python 2 way is better: individual operations for the cases where you want to handle each case specially, and a single __cmp__ function that is a simple way to handle comparisons all at once.
Perhaps, but do note that __cmp__ is *higher* level than __eq__ etc. ,
not lower level.
I'd be okay with code that detects the presence of _cmp__ and then
automatically defines __eq__ etc. accordingly. Whether this should be
default behavior or a mixin that you explicitly have to request I'm
not sure. I'd be willing to entertain a PEP that clearly explains the
motivation and puts forward a specific solution.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000