Bug 3999 and 4261
Steven Schveighoffer
schveiguy at yahoo.com
Wed Sep 1 12:36:04 PDT 2010
On Tue, 31 Aug 2010 20:59:15 -0400, bearophile <bearophileHUGS at lycos.com>
wrote:
> Daniel Gibson:
>> Then there still is the consistency-issue (anon. enums are treated
>> differently then named enums).
>
> Look at this:Se
> enum int n = 10;
> enum Color { Red, Green, Blue }
> Color color;
> if (color == Color.Red) { ...
>
> Color is a sequence of symbols, Red, Green and Blue, named Color. When
> you write your program often all you need to know is if color is Red or
> Green, and you don't care much how the compiler represents those symbols.
> The n is a compile-time constant value. It's not a sequence of something.
>
> Now, just for fun, replace the first enum with something as:
>
> ctconst int n = 10;
> enum Color { Red, Green, Blue }
> Color color;
> if (color == Color.Red) { ...
>
> ctconst is a fictional keyword that denotes compile-time constants. Now
> you are probably able to see that there is no correlation between the n
> and Color.
>
> In D they are using the same keyword by accident, probably because
> Walter thinks that saving a keyword is more important than keeping the
> semantics tidy.
AFAIK, enum meaning manifest constant was Andrei's request. And I think
if you have an idea to try and "fix" it, you might as well know now, it
will never happen. See this quote from Andrei in a bug report of mine
(bug 1961):
"And enum... you'll have to yank that out from my dead cold hands.
Extending
enum instead of adding yet another way of defining symbolic constants is
The
Right Thing to do. I am sure people would have realized how ridiculous the
whole "manifest" thing is if we first proposed it. We just can't define one
more way for each kind of snow there is."
There was a point in D2 development with the 'manifest' keyword added to
do exactly what enum now does (except for actual enumerations, for which
enum was used).
FWIW, I am not a huge fan of enum being used for meaning manifest
constants that are not enumerations, but as far as daily usage, it's not
really bad. It's somewhat of a petty problem, since enum is not
functionally deficient. It just looks weird, especially to those used to
other languages. I suppose you could think of it as an enumeration with
one member :)
-Steve
More information about the Digitalmars-d
mailing list