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

Walter Bright newshound2 at digitalmars.com
Sun Feb 16 05:57:22 UTC 2020


On 2/15/2020 7:20 PM, Steven Schveighoffer wrote:
> All these points apply to for loops and foreach loops as well. All of these can 
> be done with while loops.

It's the while loop that is redundant. foreach is key to writing generic code 
that would be impractical using for loops for.


> Yet, we don't want to remove them because they provide a good readable syntax 
> for what is required in most cases.

That's not really why. I can explain more if you like.


> In this DIP, we are exploding the verbosity and repetitiveness to an 
> uncomfortable degree, which frankly wasn't even necessary before. The brace 
> syntax is beautifully minimal.

You said you don't use this syntax. I've used it since the beginning. I wouldn't 
miss it.

Left unsaid in all this is the static initializer syntax can only be use for 
statics, and even then only for structs without a constructor. I've never heard 
a complaint about how terrible it was to use the function-style syntax, which is 
required for every other use.

As for using Voldemort types in a static initializer, good luck contriving a use 
case for that. And if one manages to do it, there's still a usable workaround - 
typeof - which Mathias used.


>> 4. anyone writing a book/tutorial on D has to become proficient with it
> Really? You have to be proficient in D struct initializers to write a book? I'm 
> pretty sure I have at least 2 D books without this in it.

Ali's book certainly does (Section 47.3). Andrei's does not, it uses the 
function style syntax.

---

BTW, if you want to present a DIP for anonymous struct literals, please do so.


More information about the Digitalmars-d mailing list