aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-12-05 19:48:06 +0800
committerGitHub <noreply@github.com>2016-12-05 19:48:06 +0800
commit34327c5d8ae0cd949bb8848048f520e48c4ee651 (patch)
treec07ec6c02ac896ad5c726c166f1000ecb11c245c
parent29edf2f4c90a39e843510a61791b42c6898a045d (diff)
parent217f33c252e8562a44c683ff1aae9de538ef475b (diff)
downloaddexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.tar
dexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.tar.gz
dexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.tar.bz2
dexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.tar.lz
dexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.tar.xz
dexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.tar.zst
dexon-solidity-34327c5d8ae0cd949bb8848048f520e48c4ee651.zip
Merge pull request #1394 from ethers/patch-1
styleguide: Order of Functions
-rw-r--r--docs/style-guide.rst81
1 files changed, 81 insertions, 0 deletions
diff --git a/docs/style-guide.rst b/docs/style-guide.rst
index 272a1b31..9aae3d7b 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 constructor and fallback definitions easier.
+
+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() {
+ ...
+ }
+
+ // 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() {
+ ...
+ }
+
+ // Internal functions
+ // ...
+ }
+
Whitespace in Expressions
=========================
@@ -194,6 +262,19 @@ No::
y = 2;
long_variable = 3;
+Don't include a whitespace in the fallback function:
+
+Yes::
+
+ function() {
+ ...
+ }
+
+No::
+
+ function () {
+ ...
+ }
Control Structures
==================