observation: D getting a bit complex

Dominikus Dittes Scherkl via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 30 02:55:00 PDT 2015


On Sunday, 30 August 2015 at 07:36:55 UTC, BBasile wrote:
> On Sunday, 30 August 2015 at 02:42:30 UTC, Spacen Jasset wrote:
>> immutable(ElementEncodingType!(ElementType!Range))[] 
>> buildPath(Range)(Range segments) if (isInputRange!Range && 
>> isSomeString!(ElementType!Range));
>> pure nothrow @safe immutable(C)[] buildPath(C)(const(C)[][] 
>> paths...) if (isSomeChar!C);
>
> this is stodgy, particularly in a console with line wrapping at 
> 80 chars.

Could have been written as

auto buildPath(Range)(Range segments)
if (isInputRange!Range && isSomeString!(ElementType!Range));

but having an explicit return type is super valuable information. 
But the opportunity to omit it makes implementing a first working 
version so fast that it is pure joy.

And the constraints you need not read - unless you want to 
understand why your call to the function failed. C++ is just 
lacking without them. Having them avoids that you always have to 
handle ridiculous input within your functions and allows to 
concentrate on meaningful code.


More information about the Digitalmars-d-learn mailing list