DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 14 22:11:36 UTC 2020


On 2/14/20 4:49 PM, Walter Bright wrote:
> On 2/14/2020 6:46 AM, Steven Schveighoffer wrote:
>> Now, imagine Vector2D and Moves are templated on type! Would be 
>> horrendous.
> 
> That's why D has alias declarations.

An alias declaration is a declaration. It needs its own line before the 
expression use. This is unwieldy as well, further squirreling away the 
definition from the usage, requiring more lookup time.

Promoting "just use an alias" means someone just "quickly" adds an alias 
to make the thing short:

alias X = Vector2D!double;

... // some many lines later

auto awsd = Moves!double(items: [X(x: 1, y: 0), X(x: 0, y: 1), X(x: -1, 
y: 0), X(x:0, y:-1)]);

Leaving the reader scratching his head at where X comes from after 
looking up the Moves layout and not seeing it there. Even with the 
alias, repeating the type over and over is really an exercise in rote 
frustration.

Especially when the compiler already knows how to figure this out 
without help (it already does this correctly with struct initializer 
syntax today).

-Steve


More information about the Digitalmars-d mailing list