Message242239
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... |
|
Date |
User |
Action |
Args |
2015-04-29 18:42:18 | Sergey.Kirpichev | set | recipients:
+ Sergey.Kirpichev, tim.peters, rhettinger, paul.moore, mark.dickinson, benjamin.peterson, r.david.murray, matrixise |
2015-04-29 18:42:18 | Sergey.Kirpichev | link | issue24075 messages |
2015-04-29 18:42:18 | Sergey.Kirpichev | create | |
|