DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion
aliak
something at something.com
Fri Feb 14 13:47:38 UTC 2020
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).
>
> And I didn't even mention templates! Imagine if a struct is an
> aggregate of other templated struct, e.g. `struct Aggregated
> (T, TV = DefaultValue) { Foo!T f1; Bar!T f2; xvector!(T, TV)
> f3; }`.
> Have fun turning a struct literal for this into something that
> spells out the type.
That'd be not fun regardless of brace initializers or not.
>
> I would strongly advise against trying to decide what is a
> "valid" use case. Just because someone approach a problem
> differently doesn't mean their solution is invalid.
If there's a bug in the type system it should be fixed. Not
maintained. Not thinking about is would be the unadvisable part
IMO.
More information about the Digitalmars-d
mailing list