Enum literals, good? bad? what do you think?
Mathias LANG
geod24 at gmail.com
Wed Jul 21 03:10:18 UTC 2021
On Tuesday, 20 July 2021 at 15:50:49 UTC, russhy wrote:
>
> So what do you think? yay? nay? why not?
>
>
> [1] https://github.com/RUSshy/DIPs/blob/patch-2/DIPs/DIP1xxx.md
The `.` syntax is ambiguous because `.` is the module-scope
operator.
There's also the question of what to do with nested enums:
```
struct Foo
{
enum Bar { A, B, }
void func () {
assert(A == 0); // Should it work ?
assert(.A == 0); // Or should it be this ?
// The above currently refers to the `struct A`.
}
}
struct A {}
```
The only time I had found enums to be too verbose is in switch
statements.
As mentioned previously, `switch (value) with `(EnumType)` helps.
I think we should make it the default (essentially `case`s should
be in a `with (typeof(value))` scope), and that would alleviate
most of the pain.
More information about the Digitalmars-d
mailing list