Feature request: Attribute with which to enable the requirement of explicit-initialization of enum variables

Jonathan M Davis jmdavisProg at gmx.com
Sun Jun 2 19:32:13 PDT 2013


On Monday, June 03, 2013 04:23:00 Andrej Mitrovic wrote:
> Thoughts?

What makes this different from normal variables? This could happen with any 
type. You're basically trying to force people to directly initialize things in 
case they have bugs if they don't. If they really care about it, they can just 
always directly initialize it themselves. And when you have code like

Machine machine;

if(something)
{
    // do a bunch of stuff
    machine = Machine.x86;
}
else
{
    //do a bunch of other stuff
    machine = Machine.x86_64;
}

you'd be forcing people to directly initialize the machine variable even if 
they didn't intend to use the value. And directly initializing the variable 
generally indicates that you're giving it a value that you intend to use 
rather than letting it be the default until you actually _do_ given it a valid 
value.

This is like how Java forces you to directly initialize things when it doesn't 
think that you've initialized them elsewhere. D did _not_ take that route. It 
when with have an init value for every type and initializing with that. The 
feature that you're suggesting would not be in line with that design decision.

- Jonathan M Davis


More information about the Digitalmars-d mailing list