On Thursday, 30 June 2022 at 11:03:08 UTC, bauss wrote:
>On Thursday, 30 June 2022 at 10:58:37 UTC, Mike Parker wrote:
>On Thursday, 30 June 2022 at 10:51:31 UTC, ryuukk_ wrote:
> >auto color = orange;
// What is color?
same, it's not .orange
therefore it's 1, if it where with the dot, it's compile error telling you to be more explicit
auto color = cast(int)orange;
// What is color?
it's not .orange
therefore it is your variable, it if were with the dot, it'd take what ever is in the enum, then apply the cast
I don't know it seems pretty obvious to me
This feature is too good to not have
My problem with this is it is not obvious at all to me. When I see .foo
, I immediately think "foo is in the parent scope", as that what is what it means right now in D. If we're suddenly seeing .foo
at module scope, now I've got a fault in my wiring; .foo
suddenly has different meanings depending on the scope in which it's used.
I mean, maybe I could get used to it if I used it. But I don't see myself using it at all.
Not saying I'm against the feature, I just don't understand why auto color = Color.orange
is a problem and how Color color = .orange
is better. Because of four fewer characters?
What it seems like it's trying to solve is this:
SomeEnum.a | SomeEnum.b | SomeEnum.c
So you could instead do:
.a | .b | .c
But much like you I don't think that's at all clarified, maybe I would settle for something like this:
SomeEnum(a | b | c) as that clearly tells you it's SomeEnum and then it's clear you're picking the values from that, so a, b and c will always be from SomeEnum.
But personally I don't really like that syntax either as it clashes too much with struct ctors and/or function calls.
So I don't have an actual good solution, so I guess in the end I'm not for any changes.
SomeEnum flags = SomeEnum (a | b | c);
Why do i have to be repetitive? the goal is to not be repetitive and be cleaner
SomeEnum flags = .a | .b | .c;
The brain no longer have to read 2x the same stuff, it goes straight to the point, it is explicit and typechecked