DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion
Steven Schveighoffer
schveiguy at gmail.com
Fri Feb 14 23:38:04 UTC 2020
On 2/14/20 6:10 PM, Walter Bright wrote:
> On 2/14/2020 1: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.
>
> You can also do:
>
> auto v(float a, float b) { return Vector2D(x: a, y: b); }
>
> and:
>
> Moves awsd = {items: [{x: 1, y: 0}, {x: 0, y: 1}, {x: -1, y: 0},
> {x:0, y:-1}]};
>
> becomes:
>
> auto awsd = Moves(items: [v(1,0), v(0,1), v(-1,0), v(0,-1)]);
>
> voila!
This is less attractive than the alias, because now I'm calling a
function for all the items (and I still need an extra declaration
somewhere).
Not only that, but you modified the parameter names, so now it's a and b
instead of x and y.
And finally, you removed the documentation of what members the call is
setting (the 'x' and 'y').
Still not as good IMO as the original call with brace style
initialization, which needs no extra framework definitions, and no
reason to search the code space for the "v" function to understand what
it is doing.
So far, this looks like a step backwards in code clarity, efficiency,
and beauty.
-Steve
More information about the Digitalmars-d
mailing list