Setting field of struct object

Renato renato at athaydes.com
Thu Jan 25 08:46:34 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`.

You know you can use struct literals in initializers, right?

```d
import std.stdio;
struct Person {
     string name, email;
     ulong age;
}

void main() {
     Person p = {name: "Joe", email: "joe at example.com", age: 30};
     writeln(p);
}
```


More information about the Digitalmars-d-learn mailing list