mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add recommendation for leading underscore, see #11764
Update docs/style-guide.rst Co-authored-by: Nuno Santos <nunofilipesantos@gmail.com> Update docs/style-guide.rst Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org> Update docs/style-guide.rst Co-authored-by: Nikola Matić <nikola.matic@ethereum.org>
This commit is contained in:
parent
6c9fc53874
commit
6216842458
@ -1284,6 +1284,21 @@ Avoiding Naming Collisions
|
||||
This convention is suggested when the desired name collides with that of
|
||||
an existing state variable, function, built-in or otherwise reserved name.
|
||||
|
||||
Underscore Prefix for Non-external Functions and Variables
|
||||
==========================================================
|
||||
|
||||
* ``_singleLeadingUnderscore``
|
||||
|
||||
This convention is suggested for non-external functions and state variables (``private`` or ``internal``). State variables without a specified visibility are ``internal`` by default.
|
||||
|
||||
When designing a smart contract, the public-facing API (functions that can be called by any account)
|
||||
is an important consideration.
|
||||
Leading underscores allow you to immediately recognize the intent of such functions,
|
||||
but more importantly, if you change a function from non-external to external (including ``public``)
|
||||
and rename it accordingly, this forces you to review every call site while renaming.
|
||||
This can be an important manual check against unintended external functions
|
||||
and a common source of security vulnerabilities (avoid find-replace-all tooling for this change).
|
||||
|
||||
.. _style_guide_natspec:
|
||||
|
||||
*******
|
||||
|
Loading…
Reference in New Issue
Block a user