Sergey B Kirpichev added the comment:

On Wed, Apr 29, 2015 at 05:44:22PM +0000, Paul Moore wrote:
> I think the documentation is fine:
> """
> The key corresponding to each item in the list is calculated once and then 
> used for the entire sorting process.
> """

Does any "sorting process" make sense for [1] or []?!  No, it
isn't.  So, it's not clear if this "process" started at all.

This not just mine opinion - most computer languages
implement the quick exit in question (see examples above).

> It's a common computer science technique

Could you provide any language that avoid this optimization?

Here is Perl 5:
http://perl5.git.perl.org/perl.git/blob/HEAD:/pp_sort.c#l367

(third example)

> Your existing code, with a check for Omega having length 1 and omitting
> the sort in that case, looks entirely reasonable to me.

(Well, then I should look for other languages, if Python devs
insist in doing useless work...)

> Maybe you could add a comment "Avoid a costly calculation of the
> key when length is 1, as we know we don't need to sort then"

I sure, for most people - the idea of sorting list with one
element will look crazy.  There is no room for any "costly
calculations".  (Common sense, nothing more.)  So, such comment
will add more questions...

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24075>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to