Enum equality test

Nick Sabalausky a at a.a
Tue Mar 23 11:36:01 PDT 2010


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:ho8k5m$5k3$1 at digitalmars.com...
> div0:
>
>>Spec explicity says enums are convertible to their base type:<
>
> Right, but I am not sure it's a good design decision. I think requiring a 
> cast can be better.
>

I absolutely agree.

>
>>Besides, use of enums should be discouraged in general.<
>
> D enums are a significant improvement over long list of normal integer 
> constant, as I see sometimes in C code. They are safer and nicer.
>

Absolutely.

>
>>It sucks maintaining code where you've thousands of switch statements all 
>>over the place; there's nearly always a better way.<
>
> Unfortunately in D there are no computed gotos yet (even if gcc supports 
> them and LLVM is starting to be able to manage them), and today D 
> back-ends aren't able to inline virtual functions, so in some situations 
> (final, in D2) they are the best solution I see in D. Sometimes I have to 
> switch over many gigabytes of data.
>

Not only that, but there are many times when trying to use something other 
than switch/enum is just simply complete overkill anyway. If I were actively 
trying to avoid enum, I'd feel like I was using Java.





More information about the Digitalmars-d-learn mailing list