Safer casts

Janice Caron caron800 at googlemail.com
Sun May 11 04:47:15 PDT 2008


On 11/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  Personally, I prefer <snip>

By your own words, that's just a personal preference.


>  It makes more sense to me to write:
>  array.sort(); or array.sort(aDelegate);
>  instead of using:
>  sort(array); or sort(array, aDelegate); or even worse:
>  sort!(aDelegate)(array);

But now you're just saying "my syntax is better than your syntax",
when both do the same thing. In addition, the D version is more
powerful, as it allows you to say:

    sort!(f)(array)

where f is a function (not a delegate). It also allows you to write

    sort!(dg, SwapStrategy.stable)(array)

to get a stable sort instead of a non-stable (but faster) sort. This
kind of flexibility offers way more power than delegates alone.
Besides which, arrays cannot implement an orderedCollection interface,
because arrays cannot implement interfaces, so you'd be limited only
to sorting custom collection classes.


>  This is why C++ is adding the
>  notion of concepts (which facilitate compile time OOP)

So is D. Shall we take bets on which language gets them first, or in
which language they will be most powerful?



More information about the Digitalmars-d mailing list