-
Notifications
You must be signed in to change notification settings - Fork 36.7k
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
doc: update enumerator naming in developer notes #21930
Conversation
Concept ACK. I guess it should be clear from the context that those are compile-time constants. Also, IIRC it is not possible to name a enum value |
Concept ACK. |
Mildly disagree with this change. I think it's nice to be able to declare variables that change at runtime as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not, considering we use enum class
.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
ACK if this better matches what is in actual use in the project. "clashes with macros" wouldn't be so much of an issue of C++ namespaced the things, but it doesn't, and as @ryanofsky already jokes they can just pop up from the kernel headers or libc headers out of nothing. |
Checked the books/literature (Stroustrup, Meyers, Lippman, Moo, etc.) and they mostly use lowercase_underscore (snake_case) with a couple of the C++98 era ones using PascalCase (UpperCamelCase). The Google style guide (https://google.github.io/styleguide/cppguide.html#Enumerator_Names) is a bit different but "use kEnumName not ENUM_NAME" for new code since 2009 for the same reasons. Currently in this project it seems to be mostly ALL_CAPS, or in newer code lowercase (in I don't have a strong opinion (on my own I'd probably use lowercase_underscore (snake_case) with scoped enums as AFAICT it's widely used nowadays) but I think the important thing is to say which naming to use and to clarify if our choice is different from the CPP Core Guidelines so people aren't confused on which style to use. |
Again just an opinion to throw in the mix, but I like |
Yes, that could be a helpful clarification too. |
If there is no rule, we shouldn't be mentioning it |
bc2f1b0
to
2cf94a8
Compare
Per the current doc, the general rule is we follow the CPP Core Guidelines, but our examples are contradictory to it (and perhaps to common usage). I found this confusing. Re-pushed an update that combines @ryanofsky's suggestion, open to feedback. |
2cf94a8
to
2d813c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 2d813c4. This looks good to me and it seems nice to move closer to cpp core guidelines and link to them even if not adopting them wholly.
Feel free to ignore my review suggestions below. I think they help but they're just my opinions and none are important.
2d813c4
to
e721833
Compare
- Update the enumerator examples to snake_case per CPP Core Guidelines https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps - Clarify that in this project enumerators may be snake_case, PascalCase, or ALL_CAPS, and to use what is seems appropriate.
e721833
to
77f37f5
Compare
Updated per @ryanofsky feedback (thanks!) and rebased for #18568. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 77f37f5. I think this is good because it modernizes the example and clarifies current conventions.
cr ACK 77f37f5 Agree with @ryanofsky regarding:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 77f37f5.
77f37f5 doc: update enum naming in developer notes (Jon Atack) Pull request description: Per our current doc, the general rule is we follow the C++ Core Guidelines, which for enumerator naming stipulate: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps ``` Don’t use ALL_CAPS for enumerators Reason: Avoid clashes with macros. ``` but our examples (and often, codebase) are contradictory to it (and perhaps to common usage), which can be confusing when a contributor needs to choose a style to use. This patch: - updates the enumerator examples to snake_case per CPP Core Guidelines - clarifies for contributors that in this project enumerators may be snake_case, PascalCase or ALL_CAPS, and to use what seems appropriate. ACKs for top commit: practicalswift: cr ACK 77f37f5 ryanofsky: ACK 77f37f5. I think this is good because it modernizes the example and clarifies current conventions. promag: ACK 77f37f5. Tree-SHA512: 7facc607fe5e1abab0f635864340143f13c2e4bb074eb17eac7d829dcd0cf244c5c617fc49d35e8774e8af1fa1205eeebe0cca81f538a2a61f6a7ba200878bc6
77f37f5 doc: update enum naming in developer notes (Jon Atack) Pull request description: Per our current doc, the general rule is we follow the C++ Core Guidelines, which for enumerator naming stipulate: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps ``` Don’t use ALL_CAPS for enumerators Reason: Avoid clashes with macros. ``` but our examples (and often, codebase) are contradictory to it (and perhaps to common usage), which can be confusing when a contributor needs to choose a style to use. This patch: - updates the enumerator examples to snake_case per CPP Core Guidelines - clarifies for contributors that in this project enumerators may be snake_case, PascalCase or ALL_CAPS, and to use what seems appropriate. ACKs for top commit: practicalswift: cr ACK 77f37f5 ryanofsky: ACK 77f37f5. I think this is good because it modernizes the example and clarifies current conventions. promag: ACK 77f37f5. Tree-SHA512: 7facc607fe5e1abab0f635864340143f13c2e4bb074eb17eac7d829dcd0cf244c5c617fc49d35e8774e8af1fa1205eeebe0cca81f538a2a61f6a7ba200878bc6
Per our current doc, the general rule is we follow the C++ Core Guidelines, which for enumerator naming stipulate:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps
but our examples (and often, codebase) are contradictory to it (and perhaps to common usage), which can be confusing when a contributor needs to choose a style to use. This patch: