Optimizing Java using D
Chris Cain via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 24 10:17:50 PDT 2014
On Monday, 23 June 2014 at 17:26:47 UTC, Andrei Alexandrescu
wrote:
> Corollary: the default sorting algorithm in std will always be
> unstable, even if for certain data types and inputs it will
> produce stable sorting. -- Andrei
I'd also like to note that this whole discussion about
restrictions and such can also be shown as an argument for why
stable sort should be the default. That is, we can prove that
with the restriction of stability that if an unstable sort will
give you suitable results then a stable sort will also give you
suitable results, but the reverse is not true.
That is, if you don't know whether relaxing the stability
requirement of the sort will give you "wrong answers" on some
inputs of your programs, sorting using a stable sort is the
correct choice. You need to have a reason to relax that
requirement before doing it.
Speed is an OK argument for choosing unstable sort as default,
but I think stronger guarantees that it will produce a correct
output for a general problem is a better argument. Relaxation of
guarantees should be an opt-in decision by a programmer only when
they know the difference doesn't matter to the problem. This sort
of logic is consistent with decisions made in the past about the
direction of D.
More information about the Digitalmars-d
mailing list