enum

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Apr 11 16:58:11 PDT 2014


On 4/11/14, 11:32 AM, Walter Bright wrote:
> On 4/11/2014 4:18 AM, Jonathan M Davis wrote:
>> I don't see much point to enums if they're not intended to list
>> all of their values.
>
> Again, bit masks, Color, etc., and to provide a simple integral type
> that behaves like an integral type yet can be overloaded and type checked.

The point here is to not hurt most for the benefit of the few. I think 
insisting on these use cases is missing that point.

> Andrei has pointed out that these uses are unsound if you desire that
> the enumeration lists all possible values, and he's right. But I don't
> think that automatically makes them pointless.

Soundness is a Big Deal(tm). It's also a false choice that assumes no 
correct design is possible. The fact that we're willing to trade 
soundness for... for what? For saving us the small effort of designing 
the feature right? That's very un-D-y.

> Heck, look at the "StorageClass" typedef in dmd's source code, and the
> list of STC macro definitions. That would make a nice D enum, and have
> some type safety too. It would be much more sound than the C method used.

That's but one anecdote. There are plenty of enums (e.g. tokens) in dmd 
alone that are not flags.

Again: I'm fine with "it's not essential and urgh we kinda botched final 
switch so we'll go with what we have although it's kind of a bummer"... 
but claiming it's actually good, that I take issue with.


Andrei



More information about the Digitalmars-d mailing list