DIP 1020--Named Parameters--Community Review Round 2

Andre Pany andre at s-e-a-p.de
Thu Sep 12 19:58:12 UTC 2019

On Wednesday, 11 September 2019 at 23:01:32 UTC, Walter Bright 
> On 9/11/2019 12:18 AM, rikki cattermole wrote:
>> But I need to confirm with you before I do this, is this for 
>> the replacement of in place struct initialization syntax?
>> If so I want to solve that, but I need to ask you how you 
>> would want it done. Since it touches upon .init, it makes me a 
>> little concerned because of dragons.
> I'm planning to replace:
>   struct S { int a, b; }
>   S s = { 1, 2 };
> with:
>   S s = S(1, 2);
> D is almost there already, but is missing the named parameter 
> feature to go all the way.
> I'm looking at other ways as well to unify and thereby simplify 
> D.

While this solves some issues, I see one major drawback. This 
example looks currently very dense. With the new syntax it 
becomes more verbose because you have to name the structures:

struct PutItemRequest
     string tableName;
     AttributeValue[string] item;

struct AttributeValue
     bool BOOL;
     string S;
     AttributeValue[string] M;
     string[] SS;

void main()
     PutItemRequest request = {
	    tableName: "table1",
		item: [
		    "field1": {S: "LALA"},
			"field2": {SS: ["A", "B", "C"]},
			"field3": {
			    M: ["fieldA": {S: "234"}]

This example is from the Amazon Web Services library I am using. 
It is rather small. Other calls uses more deep structures.

Also please note, it doesn't compile today because you can use 
struct initialization today only for arrays but not for 
associative arrays.

Kind regards

More information about the Digitalmars-d mailing list