On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote:
> No, i don't want to do:
struct EntityDef
{
    struct Stats
    {
        int hp;
    } stats;
}
Repeating the same name 3 times, i should go back to the stone age too no?
C and all other C like languages allow me to be concise
Why is it a D thing to be backward?
In the coding scheme, fields/members/methods may be at the beginning, middle, or end of the structure, or may not be identifiers to the right of the anonymous structs. In structures, a lot (I wish it was in bitfield) has been taken from C. Especially not using typedef and not having extra semicolons make D stand out even with these. As for anonymous structures, they have to be like this in order to be used with unions.
I think everything is as it should be, and even more: Please include the relevant comment line (the // characters next to the anonymous struct) in the code and be amazed by the change :)
struct Foo
{
    int bar;
    //struct {/*
    Baz baz;
    struct Baz
    {
        auto opAssign(int value)
          => baz = value;//*/
        int baz;
    }
}
void main()
{
    Foo foo;
    foo.bar = 7;
    foo.baz = 42;
    
    imported!"std.stdio".writeln(foo); /*
    with opAssign()      Anonymous
    Foo(7, Baz(42))  or  Foo(7, 42)    */
}
Thank you to the creators and maintainers of the D.
SDB@79