diff options
author | ethers <ethereum@outlook.com> | 2016-11-18 10:06:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-18 10:06:28 +0800 |
commit | 39559c1bb6ffc42f8573cada15afd2398e3d99e9 (patch) | |
tree | 0397444f9df67b92b3b9cee7a77375a02c6faf4a | |
parent | b46a14f4a8e128c08336763abf8bbf7c111f464d (diff) | |
download | dexon-solidity-39559c1bb6ffc42f8573cada15afd2398e3d99e9.tar.gz dexon-solidity-39559c1bb6ffc42f8573cada15afd2398e3d99e9.tar.zst dexon-solidity-39559c1bb6ffc42f8573cada15afd2398e3d99e9.zip |
styleguide: Ordering of functions
Ordering would help readers identify which functions they can call, and to find the "specials" (constructor and fallback function). Mixing the "specials" in the middle of the code, as well as internal functions between external and public functions, don't help readers
Based on https://github.com/ConsenSys/MultiSigWallet/issues/19
-rw-r--r-- | docs/style-guide.rst | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/docs/style-guide.rst b/docs/style-guide.rst index 272a1b31..80ffd493 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -150,6 +150,74 @@ No:: ... } +Order of Functions +================== + +Ordering helps readers identify which functions they can call, and to find the "specials" (constructor and fallback function). + +Functions should be grouped according to their visibility and ordered: + +- constructor +- fallback function (if exists) +- external +- public +- internal +- private + +Within a grouping, place the `constant` functions last. + +Yes:: + + contract A { + function A() { + ... + } + + function () payable { + ... + } + + // External functions + // ... + + // External functions that are constant + // ... + + // Public functions + // ... + + // Internal functions + // ... + + // Private functions + // ... + } + +No:: + + contract A { + + // External functions + // ... + + // Private functions + // ... + + // Public functions + // ... + + function A() { + ... + } + + function () payable { + ... + } + + // Internal functions + // ... + } + Whitespace in Expressions ========================= |