Enum alias members: yay or nay?

Jonathan M Davis jmdavisProg at gmx.com
Sun Sep 8 00:09:17 PDT 2013


On Sunday, September 08, 2013 14:45:21 Daniel Murphy wrote:
> "Andrej Mitrovic" <andrej.mitrovich at gmail.com> wrote in message
> news:mailman.980.1378598947.1719.digitalmars-d at puremagic.com...
> 
> > enum MouseAction
> > {
> > 
> >    press,
> >    
> >    release,
> >    
> >    alias click = press,  // does not reset the counter!
> >    
> >    double_click,  // equals release + 1
> > 
> > }
> > 
> > Does the alias member feature pull its weight? Or is it overkill and
> > we should drop it?
> 
> Honestly, it seems like overkill to me.
> 
> I can understand it would be an annoying bug to hit, but I doubt it would be
> that common.
> 
> Two strategies that will prevent this bug are:
> 
> 1) Put the 'alias' members directly after the member they reference
> 2) Put the 'alias' members at the end

Agreed. Both of those easily avoid this problem, and I would have argued that 
the examples which ran into this problem were bad practice precisely because 
they didn't do either of these two. Personally, I would argue that an enum 
that is intended to be have the same value as another should pretty much 
always be listed right after the one it shares a value with.

- Jonathan M Davis


More information about the Digitalmars-d mailing list