Style Guide Enum Bool Thoughts #21684

issue JeremyRubin opened this issue on April 14, 2021
  1. JeremyRubin commented at 9:29 PM on April 14, 2021: contributor

    In many places we use bool parameters to denote some effect.

    I suggest that throughout the codebase, we make an effort to (where feasible/touched) replace these with enum class.

    It's a bit more verbose, but it's already a norm to do f(/* confusing bool */ true), and it would be nice if our compiler helped us out.

    Further, it makes it easier should later code extend the functionality to add more/different options.

    In order to reduce clutter we could make a macro BoolEnum(Argument, EnabledName, DisabledName)

    Not high importance, so I don't think we should make a project out of it, but I was looking at some code recently where it would have been nice.

    Con: we don't need more structs.

  2. JeremyRubin added the label Feature on Apr 14, 2021
  3. JeremyRubin added the label Brainstorming on Apr 14, 2021
  4. JeremyRubin added the label Docs on Apr 14, 2021
  5. JeremyRubin renamed this:
    Style Guide Thoughts
    Style Guide Enum Bool Thoughts
    on Apr 14, 2021
  6. practicalswift commented at 10:57 PM on April 14, 2021: contributor

    Concept ACK: verbose but clear is preferable over terse but unclear

  7. JeremyRubin commented at 11:23 PM on April 14, 2021: contributor

    I think high value targets for this are places where we pass multiple bool params in to a function, or make use of default args.

  8. Talkless commented at 5:25 PM on April 26, 2021: none

    Concept ACK. We need clarity. I mean, this is Bitcoin.

  9. JeremyRubin commented at 7:28 PM on April 26, 2021: contributor

    Another concept is using this paradigm for return bools, which I think could be even better (since return value is otherwise unnamed, at least function parameter names are self documented).

  10. JeremyRubin commented at 7:34 PM on April 26, 2021: contributor

    Also using the paradigm:

    switch(ret) {
    case ReturnType::Yes:
    case ReturnType::No:
    }
    assert(0);
    

    would mean that we can:

    • automatically warn about expanded return values (not so with if/else)
    • avoid cases where modify code to return something that has a bool-ness that shouldn't be read

    E.g., imagine making a function go from returning a bool to a Script and having a bool operator on the Script with a different semantic. This can happen inadvertently and the compiler won't catch it. Worst is going from a bool to an integer where -1, 0, >0 has meaning.

    I don't think getting too paranoid about this matters much, but just demonstrates that there are some other niceties in refactoring.

  11. MarcoFalke commented at 12:52 PM on May 12, 2022: member

    The feature request didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

    Closing due to lack of interest. Specific pull requests with improvements are always welcome.

  12. MarcoFalke closed this on May 12, 2022

  13. DrahtBot locked this on May 12, 2023

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-15 21:14 UTC

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