Setting field of struct object

ryuukk_ ryuukk.dev at gmail.com
Mon Jan 22 15:31:17 UTC 2024


On Monday, 22 January 2024 at 11:31:11 UTC, zjh wrote:
> On Monday, 22 January 2024 at 08:54:54 UTC, zjh wrote:
>
>> ```d
>> struct Person {
>>     string name, email;
>>     ulong age;
>> }
>> Person a{"n","email",33};
>> ```
>
>
> C++ can achieve ultimate `simplicity` without violating `DRY`,
> And here, D violates the `DRY` principle!
> Moreover, as the `package level, module level, class level, 
> member level`, D language violates integrity.
> Because D has no `class level` limit.
> These are all not `serious states`.

I used to want this feature too, but i then got hit by a bug when 
i reordered the fields in the struct.. i don't want to deal with 
that stuff anymore

But we now have named arguments, so this feature could be make 
use of it, it's similar with enums, perhaps one day this could be 
revived:

https://github.com/dlang/DIPs/blob/e2ca557ab9d3e60305a37da0d5b58299e0a9de0e/DIPs/DIP1044.md

There is even a working implementation: 
https://github.com/dlang/dmd/pull/14650




More information about the Digitalmars-d-learn mailing list