So what does (inout int = 0) do?

Shammah Chancellor via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 14 23:40:31 PDT 2016


On Friday, 15 April 2016 at 03:10:12 UTC, Andrei Alexandrescu 
wrote:
> Consider:
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/range/primitives.d#L152
>
> There is no explanation to it in the source code, and the line 
> blames to 
> https://github.com/D-Programming-Language/phobos/pull/2661 
> (irrelevant).
>
> Commenting it out yields a number of unittest compilation 
> errors, neither informative about the root of the problem and 
> indicative as to how the parameter solves it.
>
> There are two issues here:
>
> 1. Once a problem/solution pair of this degree of subtlety 
> crops up, we need to convince ourselves that that's sensible. 
> If we deem it not so, we look into improving the language to 
> make the problem disappear.
>
> 2. There needs to be documentation for people working on the 
> standard library so they don't need to waste time on their own 
> discovery process.
>
> We want Phobos to be beautiful, a prime example of good D code. 
> Admittedly, it also needs to be very general and efficient, 
> which sometimes gets in the way. But we cannot afford an 
> accumulation of mad tricks to obscure the large design.
>
>
> Andrei

`(int inout = 0)` is not the only problem with that template -- 
and it's bothered me for years.

`is(typeof( () { ... } ) )` as a whole looks like a "trick" to 
me.  It's not going to be immediately obvious to someone who 
reads the D spec, and then that code, what that template does.

I think that behavioral type checks are common enough in D that 
it should have it's own first-class syntax.

-Shammah


More information about the Digitalmars-d mailing list