[PATCH] sort with key and reverse keywors in Python2.4

Andrew Bennetts andrew at canonical.com
Thu Jun 2 14:21:37 BST 2005


On Thu, Jun 02, 2005 at 09:08:11AM -0400, Aaron Bentley wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Mario Pernici wrote:
> | This patch to changeset.py uses in my_sort()  Python2.4's sort
> | with key and reverse keywords, falling back to Python2.3's sort
> | otherwise.
> 
> Is there a compelling reason to use Python 2.4's sort facilities?  I
> recognize that they're nicer, but in general, I think it's better to
> have one codepath, instead of two.  The code's cleaner that way, and
> it's easier to test.
> 
> Of course, there are always exceptions if there's a good enough reason.

The new facilities are typically much faster, due to making fewer and
simpler pure-python function calls.  How much "much faster" is in this
particular instance I've no idea...

As with any optimisation, I'd be sceptical of it without some hard numbers
demonstrating that it's worthwhile.

It's also the sort of thing that deserves a comment justifying it and
explaining it. "# Try to use Python 2.4's faster sorting, otherwise fallback
to 2.3's." would make a huge difference to readability, and make it easier
to spot and clean up this cruft when python 2.4 is considered ubiquitous
enough to drop 2.3 support in bzr.

-Andrew.





More information about the bazaar mailing list