mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
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
This commit is contained in:
parent
b46a14f4a8
commit
39559c1bb6
@ -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
|
||||
=========================
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user