enum

Jonathan M Davis jmdavisProg at gmx.com
Mon Apr 14 04:48:54 PDT 2014


On Monday, April 14, 2014 02:27:24 Ola Fosheim Grøstad" 
<ola.fosheim.grostad+dlang at gmail.com>@puremagic.com wrote:
> On Sunday, 13 April 2014 at 13:50:14 UTC, Jonathan M Davis wrote:
> > Regardless, I'd never use an enum to partially enumerate values
> > for a type,
> > because I think that that violates the very concept of what an
> > enumeration is.
> 
> Then you cannot write forward compatible code without creating
> lots of unused enum values, but I guess that is a reasonable
> tradeoff.

Well, since code needs to be able to handle all enum values appropriately, 
adding or removing enum values does tend to break code. That's why we have 
final switch - to make it so that code breaks and the problem is caught rather 
than having the code silently break.

Whether it makes sense to create unused enum values depends on what the enum 
is for, but at the moment, I can think of any enum where I would have thought 
that that was appropriate. It's pretty much just a fact of life that if you 
change the values enumerated by an enum, you're going to break code that deals 
with all of the enum values (though code that only deals with some of them can 
avoid breakage).

- Jonathan M Davis



More information about the Digitalmars-d mailing list