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

NX nightmarex1337 at hotmail.com
Mon Feb 17 13:10:15 UTC 2020


The following code is from actual real world:

VkPipelineViewportStateCreateInfo viewportStateInfo = {
	viewportCount : 1,
	pViewports    : [ {0f, 0f, 1920f, 1080f, -1f, 1f} ],
	scissorCount  : 1,
	pScissors     : [ {{0, 0}, {1920, 1080}} ],
};

If the brace-style struct initializers get deprecated this is 
what I have to write:

auto viewportStateInfo = VkPipelineViewportStateCreateInfo(
	viewportCount : 1,
	pViewports    : [ VkViewport(0f, 0f, 1920f, 1080f, -1f, 1f) ],
	scissorCount  : 1,
	pScissors     : [ VkRect2D(VkOffset2D(0, 0), VkExtent2D(1920, 
1080))) ],
);

The following is what it looks like if I use parameter names as 
well, and it's not hard to imagine having to write code like this 
if someone has complicated nested structures:

auto viewportStateInfo = VkPipelineViewportStateCreateInfo(
	viewportCount : 1,
	pViewports    : [ VkViewport(x:0f, y:0f, width:1920f, 
height:1080f, minDepth:-1f, maxDepth:1f) ],
	scissorCount  : 1,
	pScissors     : [ VkRect2D(offset: VkOffset2D(x:0, y:0), extent: 
VkExtent2D(width:1920, height:1080))) ],
);


Absolutely not ideal. Doesn't scale. Too verbose.
This feature should be improved instead of making it deprecated. 
I've never seen someone getting confused by brace-style syntax. I 
have also yet to discover any deal breaking issues about this 
feature, and it doesn't seem complicated to support **at all**.
This would also break a good amount code and that is rather hard 
to automate by conventional text editing tools. (if only people 
cared about dfix huh...)

Besides, I don't want my D code to look like java. I've had 
enough of that.


More information about the Digitalmars-d mailing list