Bug 3999 and 4261

Nick Sabalausky a at a.a
Tue Aug 31 17:16:37 PDT 2010


"Daniel Gibson" <metalcaedes at gmail.com> wrote in message 
news:mailman.24.1283298345.858.digitalmars-d at puremagic.com...
> ---
> int x;
> stream.read(x); // btw: this often sucks - why not x = stream.readInt()?

Better yet: stream.read!int()

> if(x == MyEnum.DIE)
> return 0;
> else if(x == MyEnum.CALLFOO)
> foo(x);
> ---
> or something like that (switch() might be better, but whatever).
>
> Also treating named and unnamed enums differently seems inconsistent to 
> me.
>

D's enums are *already* two completely different things. Some enums create a 
new type with a pre-determined set of possible values, and some *ahem* 
"enum"s *cough* just simply create a manifst constant and no new type.

I gotta say, I'm completely with bearophile on these enum issues. One of the 
things that drew me to D from C/C++ is the increased emphasis on *strong* 
typing, but D's enums (and the death of typedef, athough I do understand the 
reasons for that) make me feel like I'm right back in the middle of C's 
shitty so-called "type system".

Plus, even if you do want to treat a...*real* enum (such as MyEnum above) as 
little more than a series of manifest constants (which I think is terrible 
design for an enum system), then the whole point of them is to replace magic 
numbers with real names. So if they get printed out as their base type, then 
we're right back into useless "magic number" territory. I've never once, in 
any language, printed out the value of an enum variable, gotten the value of 
the *base* type, and *not* needed to convert that back into the enum symbol 
name either in my head or by looking up the enum definition (or 
mechanically). And I've rarely, if ever, in any language, printed out the 
value of an enum variable, gotten the actual symbol name and actually needed 
the value of the base type instead.





More information about the Digitalmars-d mailing list