doc: update enumerator naming in developer notes #21930

pull jonatack wants to merge 1 commits into bitcoin:master from jonatack:developer-notes-enum-naming changing 1 files +12 −8
  1. jonatack commented at 2:36 PM on May 12, 2021: member

    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.
  2. fanquake added the label Docs on May 12, 2021
  3. MarcoFalke commented at 3:05 PM on May 12, 2021: member

    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 ERROR, because this conflicts with some windows macro in our cross build. Error might work.

  4. hebasto commented at 7:49 PM on May 12, 2021: member

    Concept ACK.

  5. ryanofsky commented at 9:33 PM on May 12, 2021: member

    Mildly disagree with this change. I think it's nice to be able to declare variables that change at runtime as variable, and declare variables that don't change as CONSTANT, and just use the choice to try to make code more understandable. It's possible a constant could conflict with a preprocessor macro, though, and this could be bad. I don't check for preprocessor macros under my bed every night, and I'm not too scared of them, but maybe I should be! So ignore this feedback if this seems like the clear way to go.

  6. promag commented at 10:05 PM on May 12, 2021: member

    Why not, considering we use enum class.

  7. DrahtBot commented at 3:01 AM on May 13, 2021: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  8. laanwj commented at 12:00 PM on May 13, 2021: member

    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.

  9. jonatack commented at 2:05 PM on May 13, 2021: member

    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 src/bench/nanobench.h) or PascalCase (git grep -A5 "enum class ConnectionDirection").

    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.

  10. ryanofsky commented at 3:21 PM on May 13, 2021: member

    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 CONSTANT<<3/2 to emphasize unchangedness of expressions when enums are used as collections of constants in bitwise or arithmetic code, and I like Confused NotConfused NotConfusedAndHungry ConfusedButSleepy for readability of english words in logical / event-handling code that more closely resembles natural language. I would not want to codify this and think it's fine to have guidelines that say there is no rule, and please do what seems appropriate.

  11. jonatack commented at 8:31 AM on May 14, 2021: member

    guidelines that say there is no rule, and please do what seems appropriate.

    Yes, that could be a helpful clarification too.

  12. MarcoFalke commented at 9:19 AM on May 14, 2021: member

    If there is no rule, we shouldn't be mentioning it

  13. jonatack force-pushed on May 14, 2021
  14. jonatack commented at 9:30 AM on May 14, 2021: member

    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.

  15. jonatack force-pushed on May 14, 2021
  16. in doc/developer-notes.md:94 in 2d813c42ed outdated
      90 | @@ -91,6 +91,9 @@ code.
      91 |    - Compile-time constant names are all uppercase, and use `_` to separate words.
      92 |    - Class names, function names, and method names are UpperCamelCase
      93 |      (PascalCase). Do not prefix class names with `C`.
      94 | +  - Enumerators may be snake_case, PascalCase, or ALL_CAPS. This is a more tolerant policy than
    


    ryanofsky commented at 4:22 PM on July 13, 2021:

    In commit "doc: update enum naming in developer notes" (2d813c42ed5573d3afd80d677e2ded41e8d5b7e8)

    Suggestion to s/Enumerators/Enumerator constants/ to be clear this is referring to enum constant names not enum type names (maybe this is clear to others, but I had to look it up)


    ryanofsky commented at 4:23 PM on July 13, 2021:

    In commit "doc: update enum naming in developer notes" (2d813c42ed5573d3afd80d677e2ded41e8d5b7e8)

    Suggest using backtick quotes around snake_case, PascalCase, or ALL_CAPS


    ryanofsky commented at 4:34 PM on July 13, 2021:

    In commit "doc: update enum naming in developer notes" (2d813c42ed5573d3afd80d677e2ded41e8d5b7e8)

    I'd probably insert the new bullet point one line up so the two constant guidelines are next to each other:

    • Variable and namespace names
    • Constant names
    • Enumerator constant names
    • Class names, method names, and function names
    • Test names

    (This might require rebasing after #18568 to avoid conflicts)


    jonatack commented at 7:19 PM on July 13, 2021:

    done


    jonatack commented at 7:19 PM on July 13, 2021:

    done


    jonatack commented at 7:25 PM on July 13, 2021:

    Thanks for the heads up on rebasing. Done.

  17. in doc/developer-notes.md:95 in 2d813c42ed outdated
      90 | @@ -91,6 +91,9 @@ code.
      91 |    - Compile-time constant names are all uppercase, and use `_` to separate words.
      92 |    - Class names, function names, and method names are UpperCamelCase
      93 |      (PascalCase). Do not prefix class names with `C`.
      94 | +  - Enumerators may be snake_case, PascalCase, or ALL_CAPS. This is a more tolerant policy than
      95 | +    the [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Renum-caps).
    


    ryanofsky commented at 4:26 PM on July 13, 2021:

    In commit "doc: update enum naming in developer notes" (2d813c42ed5573d3afd80d677e2ded41e8d5b7e8)

    Would be nice to add

    , which recommend using snake_case

    to the end of this sentence to save the trouble of having to click the link to see what is suggested


    jonatack commented at 7:19 PM on July 13, 2021:

    done

  18. ryanofsky approved
  19. ryanofsky commented at 4:42 PM on July 13, 2021: member

    ACK 2d813c42ed5573d3afd80d677e2ded41e8d5b7e8. 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.

  20. jonatack force-pushed on Jul 13, 2021
  21. doc: update enum naming in developer notes
    - 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.
    77f37f58ad
  22. jonatack force-pushed on Jul 13, 2021
  23. jonatack commented at 7:26 PM on July 13, 2021: member

    Updated per @ryanofsky feedback (thanks!) and rebased for #18568.

  24. ryanofsky approved
  25. ryanofsky commented at 7:51 PM on July 13, 2021: member

    ACK 77f37f58ad2f349cecb2eda28b415267d3d7d76e. I think this is good because it modernizes the example and clarifies current conventions.

  26. practicalswift commented at 8:28 PM on July 24, 2021: contributor

    cr ACK 77f37f58ad2f349cecb2eda28b415267d3d7d76e

    Agree with @ryanofsky regarding:

    […] it seems nice to move closer to cpp core guidelines and link to them even if not adopting them wholly.

  27. promag commented at 5:31 PM on September 5, 2021: member

    ACK 77f37f58ad2f349cecb2eda28b415267d3d7d76e.

  28. MarcoFalke merged this on Sep 6, 2021
  29. MarcoFalke closed this on Sep 6, 2021

  30. jonatack deleted the branch on Sep 6, 2021
  31. sidhujag referenced this in commit 1cac4e22e1 on Sep 7, 2021
  32. PastaPastaPasta referenced this in commit f40055446b on Apr 3, 2022
  33. DrahtBot locked this on Sep 6, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me