Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Enum members style guide #8984

Closed
asterite opened this issue Apr 1, 2020 · 6 comments
Closed

[RFC] Enum members style guide #8984

asterite opened this issue Apr 1, 2020 · 6 comments

Comments

@asterite
Copy link
Member

asterite commented Apr 1, 2020

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:

  • PascalCase
  • SCREAM_CASE

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.

@asterite
Copy link
Member Author

asterite commented Apr 1, 2020

Let's also vote to see trends.

  • PascalCase 😄
  • SCREEM_CASE 🚀

@Blacksmoke16
Copy link
Member

What about Pascal_Snake_Case? This way you would be able to tell the difference between a type, a constant, and enum member visually.

@Sija
Copy link
Contributor

Sija commented Apr 1, 2020

PascalCase IMO is nicer for the eyes but in the case of abbreviations SCREAM_CASE is more readable: HTMLAttr vs HTML_ATTR

@girng
Copy link
Contributor

girng commented Apr 1, 2020

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.

@straight-shoota
Copy link
Member

Duplicate of #7270. I would like to continue the discussion there.

@asterite
Copy link
Member Author

asterite commented Apr 2, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants