| |
| Posted by ryuukk_ in reply to Nick Treleaven | PermalinkReply |
|
ryuukk_
Posted in reply to Nick Treleaven
| On Saturday, 4 January 2025 at 20:01:33 UTC, Nick Treleaven wrote:
> On Thursday, 2 January 2025 at 21:14:25 UTC, ryuukk_ wrote:
> On Thursday, 2 January 2025 at 19:08:06 UTC, Walter Bright wrote:
> On 1/2/2025 6:32 AM, Derek Fawcus wrote:
> The closest native equivalent in D, would seem to be the following, making use of the new facility.
struct outer {
int a;
struct inner_ {
int b;
int c;
}
inner_ inner;
int d;
alias b = inner.b;
alias c = inner.c;
};
Or is there a nicer way to write that in D?
struct outer {
int a;
struct {
int b;
int c;
}
int d;
}
that's hard to learn, why is it possible to do outter.b = 42 ?
That's how it works in C11. The spec shows some useful use cases:
https://dlang.org/spec/struct.html#anonymous
> struct outer {
int a;
struct {
int b;
int c;
} inner;
int d;
}
now it is easier to learn, it is an anonymous struct called inner
That complicates the parser, beginners would forget to type the ; after a struct definition and get confused at the parse errors.
Why do you need an anonymous struct type there? Naming it and using the struct name for inner isn't difficult, and it doesn't seem needed that often.
It's same story with tagged union, tuples, .enum, if you don't see them as improvements, there is nothing to argue about, try to use a language that supports them all, and you'll realize that it's like stepping up and upgrading your toolbox
You don't need class anymore, you don't need OOP anymore, you get empowered to use data driven development and it just is better
|