3 ms·
I've always respected choosing 0 as an invalid state. It makes it much harder to accidentally have a function succeed if the default representation is "you mess
by dwattttt 3y ago
I've always respected choosing 0 as an invalid state. It makes it much harder to accidentally have a function succeed if the default representation is "you messed up"
- naruhodo 3y agoWouldn't that mean that you should just define ERROR as the first enumeration constant, with value 0, rather than break out of the enum type? It's really common though to use enums as array indices, which start at 0.
- dwattttt 3y agoIn practice I always choose the first enumeration to be a specific error of "you failed to initialise this". I don't know that I've ever directly used an enum as an index, but I guess if I did I'd have to bias it.