list.sort, was Re: [Python-Dev] decorate-sort-undecorate
Kevin J. Butler
python-kbutler at sabaydi.com
Wed Oct 15 20:50:09 EDT 2003
Michael Chermside wrote:
> Make it <wink> 999 after my -1. Seriously, the BDFL isn't just
> making this up.
A brief google search showed that the python posters whose names I
recognize automatically who had expressed opinions were about evenly
split on the issue. (I was startled to see my own name - that was where
I came across my post of six years ago.)
So yes, Guido isn't alone. (If he were, he _probably_ would have caved
in to peer pressure. Maybe not, though...)
> Beginners would be tripped up by this ALL the
> time. People like me who move from language to language and
> can never remember which behavior goes with which language would
> be tripped up.
I have yet to see a convincing code example (e.g., "Here is some real
code - look how confused people would be if list.sort() had returned
self"). Generally, list.sort() returning self would make the code more
clear & concise.
In contrast, I've seen multiple people say that using list.sort() in an
expression caused real bugs (one said it was his most common Python
bug), and many express irritation about the final code. (Especially
people with a functional programming background, but I'm not one of them.)
> Returning None prevents being tripped up. And
> the work-around is *a 2-line function*! Why can't YOU live with
> writing a 2-line helper function to save lots of frustration
> for those of us who might forget whether it's in-place or not?
Oh, we have!
Concrete frustration outweighs speculative frustration. ;-)
(pun intended).
Or maybe we could have list.sort()
return "Error: .sort method does not return self."
That would make the following idiom entertaining:
for i in list.sort():
print i
kb
More information about the Python-Dev
mailing list