python 3's adoption
steven at REMOVE.THIS.cybersource.com.au
Wed Jan 27 07:12:50 CET 2010
On Wed, 27 Jan 2010 02:28:00 +0100, Alf P. Steinbach wrote:
>>> * Print is now a function. Great, much improvement.
> Actually not, IMHO. All it does is is to provide incompatibility. They
> forgot Ronald Reagan's old maxim: if it don't need fixin', don't fix it.
print as a function is more consistent and more convenient than print as
a statement. Or to put it another way, print as a statement is less
consistent and convenient, and therefore in need of fixing. By Ronald
Reagan's aphorism, it should be fixed, and now does.
Of course there's a bit of a learning curve for those used to the old
ways, but in two years from now, I expect no-one will remember what the
fuss was about. Python 2.6 users will start their script with "from
__future__ import print_function", Python 2.7 users may not even need to
do that, and we'll all pity those stuck with 2.5 or 2.4.
>>> * Many functions that return lists now returns “Views” or
>>> “Iterators” Instead. A fucking fuck all fucked up shit. A extraneous
>>> “oop engineering” complication. (See: Lambda in Python 3000)
> On the contrary, this is a great improvement.
>>> * The cmp() function used in sort is basically gone, users are now
>>> supposed to use the “key” parameter instead. This is a flying-face-
>>> fuck to computer science. This would be the most serious fuckup in
>>> python 3. (See: Sorting in Python and Perl)
> I agree. :-)
I did too, when I first heard cmp was to be dumped. But I changed my mind
and now agree with the decision to drop cmp. Custom sorts are nearly
always much better written with key rather than cmp: key adds an O(N)
overheard to the sorting, while cmp makes sorting O(N**2). In other
words, key is *much* faster, and generally easier to write as well.
There may be a handful of rare applications where there is no obvious way
to convert a cmp function to a key, but they are vanishingly rare. I
think, if you search the archives, Paul Rubin may have come up with one
example. There are a number of recipes for easily converting cmp sorts to
I think, in my perfect world, list.sort() and sorted() should continue
being key based, while the standard library contained (perhaps in the
functools module?) a sort function that contains all the bells and
whistles. You want cmp, it's there, and you can pay the extra cost if you
need it. You want to sort multiple lists by the contents of one? One
import away. But keep the general sort() function lean and super-fast.
More information about the Python-list