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

matheus matheus at gmail.com
Fri Feb 14 14:04:43 UTC 2020


On Friday, 14 February 2020 at 13:47:38 UTC, aliak wrote:
> On Friday, 14 February 2020 at 07:54:56 UTC, Mathias Lang wrote:
>>> You have auto?
>>
>> The real inconvenience shows up as you nest structure, which 
>> was in the second part of the quote.
>>
>> Consider `auto f = Foo(a: SomeType(b: SomeOtherType(x: 
>> 42)));`, it is not quite as readable as the struct literal 
>> alternative, and there's no way to use `auto` here, even 
>> though the expected type is known to the compiler and 
>> unambiguous.
>
> I'm not sure I see where you're repeating types there. As for 
> readability, I find
>
> Foo f = { ber: { a: 42, b: 84 } };
>
> Less readable than:
>
> auto f = Foo( ber: Ber( a: 42, b: 84 ) );
>
> (I've duplicated your spacing choices, but the extra type 
> information is more useful to me at the call site).

In this case I prefer the First one:

> Foo f = { ber: { a: 42, b: 84 } };

Matheus.


More information about the Digitalmars-d mailing list