PhobosWatch: manifest => enum

Walter Bright newshound1 at digitalmars.com
Fri Dec 28 20:33:33 PST 2007


Steven Schveighoffer wrote:
> You missed the point of my example :)  I'm not debating anonymous 
> enumerations and whether they should exist or not.  I'm saying that the 
> definition of enum working like an enumeration, or working like a manifest 
> list, based on whether the enumeration is named or anonymous, is confusing. 
> If you look at the example, the type of the value changes from one version 
> to the next, even though no type is specified.

That's a good point.

>> Extending it to allow heterogeneous types is not a big step, nor does it 
>> break any existing code or usage.
> 
> Just because you can do something that changes the meaning of a keyword, 
> especially to a meaning that is not described well by the english meaning of 
> the word, and still have existing code compile, doesn't mean you should.

It doesn't mean you shouldn't, either. This goes on all the time in 
programming languages. After all, ! doesn't mean exclamation. The reason 
we even have to invent programming languages is because english is too 
imprecise and ambiguous. If anyone tries to learn programming by using 
Webster's, they're in for some pretty tough sledding :-)

That said, I would still shrink from using an utterly contradictory 
meaning, like having the keyword "and" actually do an "or", but there 
isn't that problem here.


> Having heterogeneous types in the same enum braces is a big step, because it 
> fundamentally says 'enum is not an enumeration'.

I don't see any fundamental reason why an enumeration's contents must 
all be the same type. You could convincingly argue that they all must be 
somehow related to each other, but that doesn't require they be related 
by type. Grouping semantically related ones together would be the 
purview of the programmer.



More information about the Digitalmars-d mailing list