Enum literals, good? bad? what do you think?
Mathias LANG
geod24 at gmail.com
Thu Jul 22 03:47:55 UTC 2021
On Wednesday, 21 July 2021 at 06:19:20 UTC, Walter Bright wrote:
>>
>> The only time I had found enums to be too verbose is in switch
>> statements.
>> As mentioned previously, `switch (value) with `(EnumType)`
>> helps.
>
> Yup.
>
>> 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.
>
> Sorry, I'm not understanding the pain.
What I meant was that instead of recommending our users to use
`switch (value) with `(EnumType)`, we could just make it the
default since it's the common case with enums. Unless we think
that requiring the type of the enum be spelt out is better.
It could add to the long list of those usability enhancements
that are a hallmark of D (like `_` in number literals). I
personally don't mind the verbosity, but I heard this complaint a
few times over the years.
More information about the Digitalmars-d
mailing list