This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sergey.Kirpichev
Recipients Sergey.Kirpichev, benjamin.peterson, mark.dickinson, matrixise, paul.moore, r.david.murray, rhettinger, tim.peters
Date 2015-04-29.18:42:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20150429184211.GA1710@darkstar.order.hcn-strela.ru>
In-reply-to <1430329462.57.0.730793521635.issue24075@psf.upfronthosting.co.za>
Content
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...
History
Date User Action Args
2015-04-29 18:42:18Sergey.Kirpichevsetrecipients: + Sergey.Kirpichev, tim.peters, rhettinger, paul.moore, mark.dickinson, benjamin.peterson, r.david.murray, matrixise
2015-04-29 18:42:18Sergey.Kirpichevlinkissue24075 messages
2015-04-29 18:42:18Sergey.Kirpichevcreate