Enum alias members: yay or nay?

Daniel Murphy yebblies at nospamgmail.com
Sat Sep 7 21:45:21 PDT 2013


"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

A possible alternative would be to warn/error on having two implicitly 
initialized enum members that get the same value.

eg

enum E
{
  a,
  b,
  c = a,
  d,  // Warning: Enum member E.d has been automatically assigned the same 
value as E.a
}

tl;dr I don't think this justifies a new feature.  A lint rule, absolutely. 
A warning, possibly.  But not a new feature. 




More information about the Digitalmars-d mailing list