This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tixxit
Recipients LeWiemann, gvanrossum, rhettinger, tixxit
Date 2009-12-04.22:26:54
SpamBayes Score 7.277251e-11
Marked as misclassified No
Message-id <1259965617.88.0.0338574092292.issue1771@psf.upfronthosting.co.za>
In-reply-to
Content
I am not sure I understand the reasoning behind removing the cmp
parameter (and agree with Lea Wiemann). Trying to wedge a proper
comparison into the key parameter is clumsy and unreadable (as can be
seen in the 2to3 example above). The intrinsic ordering on objects does
not necessarily match up with the way you want to sort them. For
example, a natural intrinsic order on 2 points in 2d is lexicographical,
however you often want to sort by angular order relative to some other
point instead. Clearly this can never be put in __cmp__ or __lt__,
because the sorted order is relative to some other unknown point. Trying
to do this with the key function doesn't make sense; it would not be
clear you are sorting by angular order and you'd have to instantiate a
bunch of wrapper objects just to do basic sorting. Another quick example
would be sorting hyperplanes by intersection on a ray. Sorting points
along a direction given by a vector.

I understand removing redundant features from a language, but I just
can't see how key replaces this functionality in a readable or efficient
way. This highlights an important class of cases (since it was mentioned
that none could be thought of) in which we wish to make comparisons
between values where a comparison (<, > or ==) is more numerically
sound, more efficient, or the only option (perhaps the ordering is
defined explicitly) then computing the exact values (eg. angle). As far
as it seems, the only way to do this with key is by following the
example given and creating a class solely to wrap each object that
overrides __cmp__, which is certainly non-obvious (ie. there is no one,
obvious way to do it).
History
Date User Action Args
2009-12-04 22:26:58tixxitsetrecipients: + tixxit, gvanrossum, rhettinger, LeWiemann
2009-12-04 22:26:57tixxitsetmessageid: <1259965617.88.0.0338574092292.issue1771@psf.upfronthosting.co.za>
2009-12-04 22:26:56tixxitlinkissue1771 messages
2009-12-04 22:26:55tixxitcreate