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

Allow mixedCase in the constants naming style #14270

Open
CodeSandwich opened this issue May 25, 2023 · 5 comments · May be fixed by #14425
Open

Allow mixedCase in the constants naming style #14270

CodeSandwich opened this issue May 25, 2023 · 5 comments · May be fixed by #14425
Labels
documentation 📖 low impact Changes are not very noticeable or potential benefits are limited. needs investigation style guide Modification of the Solidity Style Guide

Comments

@CodeSandwich
Copy link

CodeSandwich commented May 25, 2023

Page

https://docs.soliditylang.org/en/latest/style-guide.html#constants

Abstract

The situation

Currently the only accepted naming convention for constants is SCREAMING_SNAKE_CASE. This leads to weird APIs, for example:

contract Four {
    uint8 public constant FOUR_CONSTANT = 2 + 2;
    uint8 public immutable fourImmutable = 2 + 2;
    function fourFunction() public pure returns (uint8) {
        return 2 + 2;
    }
}

For the consumers of the API, it's all the same, they see 3 pure functions returning uint8s, but while fourImmutable() and fourFunction() are consistent, FOUR_CONSTANT() is completely different, even though it behaves exactly as the rest.

For the devs writing contracts deriving from Four, fourImmutable and FOUR_CONSTANT are in most contexts equivalent, the only exception are assigning to other constants and static array sizes.

For the devs of Four, a cosmetic change of fourImmutable or fourFunction into a constant is an API-breaking change even though it can't affect any consumers. A change of FOUR_CONSTANT into an immutable or a function won't affect the API consumers either, it will only affect the constant evaluation in the deriving contracts.

Because the naming convention is defined in the Solidity language's own documentation, it's considered the (soft) law. All the code linters and analyzers, and also all the devs require using the SCREAMING_SNAKE_CASE for constants, to do otherwise one needs to overcome both the tools and the people.

The solution

The solution is to allow both SCREAMING_SNAKE_CASE and mixedCase names in constants, but recommend mixedCase. It won't make the existing code and interfaces break the style, after all they can't be changed anymore. Over time the tools will start accepting mixedCase, and the devs will learn to use them. The future APIs will stick to mixedCase everywhere and won't expose their inner implementation details via the naming convention anymore.

Pull request

None yet, let's discuss it first.

@ekjotsinghmakhija
Copy link

Hi, @CodeSandwich I'm new to Solidity Project and would like to start contributing with Documentation. Can you please assign it to me.

@CodeSandwich
Copy link
Author

Hi @ekjotsinghmakhija, sorry, but I can't, I'm not a maintainer 🤷

@CodeSandwich
Copy link
Author

@github-actions
Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Oct 17, 2023
@CodeSandwich
Copy link
Author

It's not stale.

@github-actions github-actions bot removed the stale The issue/PR was marked as stale because it has been open for too long. label Oct 18, 2023
@mehtavishwa30 mehtavishwa30 added the style guide Modification of the Solidity Style Guide label Mar 1, 2024
@mehtavishwa30 mehtavishwa30 added the low impact Changes are not very noticeable or potential benefits are limited. label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 📖 low impact Changes are not very noticeable or potential benefits are limited. needs investigation style guide Modification of the Solidity Style Guide
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants