Another idiom I wish were gone from phobos/druntime

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 4 16:35:48 PST 2015


Andrei Alexandrescu:

>             auto opSlice(size_t low, size_t high)
>             in
>             {
>                 assert(low <= high);
>             }
>             body
>             {
>                 import std.range : take;
>                 return this[low .. $].take(high - low);
>             }
>
> which of course trivially boils down to:
>
>             auto opSlice(size_t low, size_t high)
>             {
>                 assert(low <= high);
>                 import std.range : take;
>                 return this[low .. $].take(high - low);
>             }
>
> What advantage could possibly be in transforming a 5-liner into 
> a 9-liner?

Contracts can be read by tools, and they are part of the function 
signature. Contracts should be encouraged and increased, not 
discouraged.

Bye,
bearophile


More information about the Digitalmars-d mailing list