I think it's time we decide on what we prefer when naming enum members. As usual, the only requirement is that they start with an uppercase letter. But in the standard library we should be consistent.
Two options:
I prefer PascalCase. The reason is that, even though enum members can be seen as constants, general constants can hold arbitrary types, but enum members only integers. So if you see Foo::SCREEM_CASE
you will probably think it's some cached value, or a singleton instance. But if you see Foo::Bar
being assigned to something, or compared against, you will probably think it's an enum member. (It could be a type too, but it's less common to move and compare types around.)
Also, I think this looks nicer (all of this is subjective, of course):
Color::Red
Color::Green
Color::SkyBlue
# vs.
Color::RED
Color::GREEN
Color::SKY_BLUE
But I'd like to know your opinion.
If we agree on a style, we should apply it throughout the standard library, and write about it in the style guide.
Let's also vote to see trends.
What about Pascal_Snake_Case
? This way you would be able to tell the difference between a type, a constant, and enum member visually.
_PascalCase_ IMO is nicer for the eyes but in the case of abbreviations _SCREAM_CASE_ is more readable: HTMLAttr
vs HTML_ATTR
For me, it depends on the context. If I'm creating an enum for game commands for a gameserver, I like it to all be uppercase. If I'm creating an enum for Colors or Settings, I prefer PascalCase.
Duplicate of #7270. I would like to continue the discussion there.
Oh, I searched "enum style guide" or similar but couldn't find that other issue. Thanks! I'll close this.
But noting that PascalCase was voted unanimously, so I think we should go with that.
Most helpful comment
Let's also vote to see trends.