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

Walter Bright newshound2 at digitalmars.com
Fri Feb 14 21:35:10 UTC 2020


On 2/13/2020 9:53 PM, Mathias Lang wrote:
> 1) The type name has to be repeated.
>      So as mentioned, `Foo f = (42, 84);` would be more readable than `Foo f = 
> Foo(42, 84);`.

    auto f = Foo(42, 84);  // no repetition


>      This gets worse when a struct contains nested struct definitions, as Andre 
> pointed out (here: https://github.com/dlang/DIPs/pull/169#issuecomment-532830320).

I replied to him there.


> --- definition.d
> module definition;
> 
> struct Foo
> {
>      private struct Bar
>      {
>          int a;
>          int b;
>      }
> 
>      Bar ber;
> }
> 
> --- main.d
> module main;
> import definition;
> 
> void main ()
> {
>      Foo f = { ber: { a: 42, b: 84 } };
> }
> ```
> 
> To replace this usage, one has to use `typeof(Foo.ber)`. Even more verbose.

For private structs like that, it's time to use an actual constructor. Frankly, 
allowing { } initializers for a private struct should be a bug, not a feature.


> 3) It's way, way too early to deprecate them. There is currently *no replacement 
> available*. Some libraries try to keep compatibility for many versions (e.g. 
> Vibe.d) and some projects tests with compilers that go way back (GDC-9 is the 
> 2.076 FE and still used).

It's not a problem to stretch this out over time.


> This fits your own definition of "shuffling things around to no benefit".

Significantly simplifying the language is not shuffling.




More information about the Digitalmars-d mailing list