[Python-Dev] decorate-sort-undecorate

François Pinard pinard at iro.umontreal.ca
Tue Oct 14 08:28:01 EDT 2003

[Guido van Rossum]
> After reading this exchange, I'm not sure I agree with Tim about the
> importance of avoiding to compare the full records.

It could be useful to avoid comparing the full records.  Once in a
while, I have the problem of comparing objects which are not comparable
to start with, and have to choose between making them comparable, or
using decoration for the time of the sort in which there is a guarantee
that the object themselves will not be used in comparisons (by ensuring
decoration keys never compare equal).  The third option, providing a
comparison function, is something I succeeded to avoid so far, as it
seems to me that this is a good habit relying on fast idioms at hand,
instead of on speed-impacting formulations, and good habits are best
kept by sticking to them. :-)

The problem at making objects comparable is that you fix a preferred or
"natural" ordering for the objects, which might not be so "natural" when
you need to sort them differently.  In some circumstances, maybe many of
them, it is significantly cleaner to leave the objects as not comparable.

François Pinard   http://www.iro.umontreal.ca/~pinard

More information about the Python-Dev mailing list