Enum literals, good? bad? what do you think?

Danni Coy danni.coy at gmail.com
Wed Jul 21 02:21:24 UTC 2021


On Wed, Jul 21, 2021 at 1:56 AM russhy via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> Hello
>
> I all the time wondered why we always have to be so much verbose
> with enum, when it's not casting to primitives, it is about
> repeating their long type name, constantly, all the time
>
> After trying some other languages over the past few years, i
> discovered in zig you can just ommit the enum type name and just
> use enums this way: .MY_VALUE
>
> I don't know if that's something that could be supported with D,
> i am not a compiler dude, so i don't have the answer
>
> Adam on discord mentioned using with(ENUM_TYPE) or just an alias,
> but i think we go ahead and make it simple
>
> I had prepared a DIP [1], not ready at all, but i wanted to
> initiate some discussion about that feature
>
> So what do you think? yay? nay? why not?
>
>
> [1] https://github.com/RUSshy/DIPs/blob/patch-2/DIPs/DIP1xxx.md

When I work in C/C++ and other similar languages, I find that on
anything beyound a trivial program and particularly in a library
a namespace gets baked into the variable name. When using D I  find
that the verbosity works out to be the same for example SDL_INIT_VIDEO
becomes SDL_INIT.VIDEO
and then I end up with less verbosity in a switch using with as other
people have mentioned.


More information about the Digitalmars-d mailing list