On 10/30/07, Adam Olsen <[EMAIL PROTECTED]> wrote:
> It's clear to me that the opposition to removing __cmp__ comes down to
> "make the common things easy and the rare things possible". Removing
> __cmp__ means one of the common things (total ordering) becomes hard.
I don't really think that's it. I don't see much of a difference in
difficulty between writing::
class C(TotalOrderingMixin):
def __lt__(self, other):
self.foo < other.foo
def __eq__(self, other):
self.foo == other.foo
or writing [1] ::
class C(object):
def __cmp__(self, other):
if self.foo < other.foo:
return -1
elif self.foo < other.foo:
return 1
else:
return 0
The main motivation seems really to be efficiency for a particular
task. For some tasks, e.g. sorting, you really only need __lt__, so
going through __cmp__ will just be slower. For other tasks, e.g.
comparing objects with several components, you know you have to do
both the __lt__ and __eq__ comparisons, so it would be wasteful to
make two calls when you know you could do it in one through __cmp__.
So it's not really about making things easier or harder, it's about
making the most efficient tool for the task available.
Steve
[1] Yes, of course, you could just write cmp(self.foo, other.foo), but
this is how it's been written in the rest of the thread, so I have to
assume that it's more representative of real code.
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com