Allow designated initialization of struct

ryuukk_ ryuukk.dev at gmail.com
Fri Nov 1 12:26:25 UTC 2024


On Thursday, 31 October 2024 at 06:24:44 UTC, Salih Dincer wrote:
> On Wednesday, 30 October 2024 at 17:02:24 UTC, ryuukk_ wrote:
>> 
>> D can do it, it just needs to stop limiting people on purpose, 
>> again, if it wants to attract the C crowd, it needs to offer 
>> better, not worse, otherwise people snub D
>
> I don't think like you. Already with ImportC, D has achieved a 
> great superiority. I mean, it's not like you said, because 
> they're coming in droves :) This video was a harbinger of this, 
> and 2 years have passed and the D language has matured a lot. I 
> can't even think about 2 years from now. Wonderful
>
> https://youtu.be/2ImfbGm0fls?si=_IZDi5bxfwLoMNBv
>
> SDB at 79

Ok let's try it this way:


```D
struct Other
{
     int a;
}

struct Data
{
     Other other;
}

void pass(Data data)
{
}
void main()
{

     // THIS OK
     Data data = {
         other: { a: 42 }
     };

     // THIS OK
     pass( Data(other: Other(a: 42)));


     // WHY THIS NOT OK??
     // pass( Data { other: {a: 42} } );

     // WHY THIS NOT OK??
     //pass( Data(other: {a: 42}));
}
```


Why limit for no reason what you can do with D

Why force people to repeat themselves `other: Other(a: 42)`?


This is the thing D does worse than all of the competition that 
aim to replace C, even C3 does better... C3...


```C

struct Other
{
     int value;
}

struct Data
{
     Other[] other;
}

fn void pass(Data data)
{
}

fn void main()
{
     pass( { .other = { {.value=42} } } );
}

```

This builds

This also build:

```C
enum State
{
     IDLE,
     RUN,
     ATTACK,
}


fn void main()
{
     State state = IDLE;
     if (state == RUN) {
         // run
     }
}
```

D needs to to better



More information about the dip.ideas mailing list