refactor: improve readability of numeric literals in consensus parameters and network settings #29444

pull paplorinc wants to merge 2 commits into bitcoin:master from paplorinc:paplorinc/add-source-digit-separators-for-important-constants changing 6 files +14 −12
  1. paplorinc commented at 9:28 am on February 18, 2024: contributor

    This commit enhances the readability of large numeric literals across various parts of the Bitcoin Core codebase by introducing thousands separators (’), leveraging the C++14 digit separator feature.

    This readability enhancement follows the precedent set in various places within the Bitcoin Core codebase and aligns with ongoing efforts to improve code quality and developer experience: delimiters were already used in a few places, even in comments:

  2. DrahtBot commented at 9:28 am on February 18, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29432 (Stratum v2 Template Provider (take 3) by Sjors)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. Improve readability of numeric literals in consensus parameters
    This commit enhances the readability of large numeric literals across various consensus-related constants by introducing thousands separators ('), as per the C++14 digit separator feature. Changes are made in chainparams.cpp, amount.h, and consensus.h to include separators in the definition of constants such as nSubsidyHalvingInterval, COIN, MAX_MONEY, MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_WEIGHT, and MAX_BLOCK_SIGOPS_COST. This update aims to improve code clarity without affecting functionality.
    
    - Utilize the C++14 digit separator to make large numbers more readable.
    - Update nSubsidyHalvingInterval in chainparams.cpp for MAIN, TESTNET, and SIGNET chains.
    - Enhance clarity of COIN and MAX_MONEY in amount.h.
    - Apply readability improvements to MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_WEIGHT, and MAX_BLOCK_SIGOPS_COST in consensus.h.
    d3d41e202b
  4. paplorinc force-pushed on Feb 18, 2024
  5. paplorinc renamed this:
    Improve readability of numeric literals in consensus parameters
    Improve readability of numeric literals in consensus parameters and network settings
    on Feb 18, 2024
  6. fjahr commented at 4:33 pm on February 18, 2024: contributor
    Hi @paplorinc, I’m not convinced we need to change the formatting in these particular places. We usually do such refactorings when the code in question is being touched in a PR anyway, otherwise we try to avoid the noise. But I would support it if you open a PR recommending the use of numeric literals in our coding style guidelines (doc/developer-notes.md).
  7. Update developer-notes.md with digit separator recommendation 9d89358f34
  8. paplorinc commented at 5:14 pm on February 18, 2024: contributor

    Hey @fjahr, thanks for the quick feedback.

    I have targeted these numbers, since they’re quoted to normies all the time when asking “so how do you know there isn’t an inflation bug in Bitcoin” and I can just show them:

    I think it looks more reassuring if it’s organized as such. What do you think? I suspect that some lines will have to be refactored in dedicated PRs, since we won’t accidentally just touch these otherwise…

  9. paplorinc renamed this:
    Improve readability of numeric literals in consensus parameters and network settings
    refactor: improve readability of numeric literals in consensus parameters and network settings
    on Feb 20, 2024
  10. DrahtBot added the label Refactoring on Feb 20, 2024
  11. fanquake commented at 3:31 pm on February 20, 2024: member
    Thanks, however we don’t generally refactor consensus code for the sake of readability, so we’ll leave this as-is for now.
  12. fanquake closed this on Feb 20, 2024

  13. paplorinc commented at 4:02 pm on February 20, 2024: contributor
    Hey @fanquake, thanks for your review. Can you tell me when you’d expect consensus code to be changed otherwise?
  14. maflcko commented at 4:17 pm on February 20, 2024: member

    Thank you for your contribution. While this stylistic change makes sense on its own, it comes at a cost and risk for the project as a whole. The weak motivation for the change does not justify the burden that it places on the project. A burden could be any of the following:

    • Time spent on review
    • Accidental introduction of bugs
    • (Silent) merge conflicts, either in the branch or a backport branch. Those conflicts demand further developer and reviewer time or introduce bugs.

    For more information about refactoring changes and stylistic cleanup, see

    Generally, if the style is not mentioned nor enforced by the developer notes, we leave it up to the original author to pick whatever fits them best personally and then leave it that way until the line is touched for other reasons.

    Let us know if you have any questions.

  15. paplorinc commented at 4:48 pm on February 20, 2024: contributor
  16. paplorinc deleted the branch on Aug 9, 2024

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: 2024-12-23 03:12 UTC

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