From 39559c1bb6ffc42f8573cada15afd2398e3d99e9 Mon Sep 17 00:00:00 2001 From: ethers Date: Thu, 17 Nov 2016 18:06:28 -0800 Subject: [PATCH 1/5] 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 --- docs/style-guide.rst | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/style-guide.rst b/docs/style-guide.rst index 272a1b310..80ffd493b 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 ========================= From 549bca149408262341375f39a75e878e68d2df6b Mon Sep 17 00:00:00 2001 From: ethers Date: Thu, 17 Nov 2016 18:09:22 -0800 Subject: [PATCH 2/5] Don't include a whitespace in fallback function --- docs/style-guide.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/style-guide.rst b/docs/style-guide.rst index 80ffd493b..b0560917b 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -173,7 +173,7 @@ Yes:: ... } - function () payable { + function() payable { ... } @@ -210,7 +210,7 @@ No:: ... } - function () payable { + function() payable { ... } From 1d9aee97c2532d57bd27e65f8b22079ebbe71e3a Mon Sep 17 00:00:00 2001 From: ethers Date: Thu, 17 Nov 2016 18:13:33 -0800 Subject: [PATCH 3/5] styleguide: Don't include a whitespace in the fallback function --- docs/style-guide.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/style-guide.rst b/docs/style-guide.rst index b0560917b..46b915e1b 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -262,6 +262,19 @@ No:: y = 2; long_variable = 3; +Don't include a whitespace in the fallback function: + +Yes:: + + function() { + ... + } + +No:: + + function () { + ... + } Control Structures ================== From feebe3e7555a6977acd787d255cb8a2f085a4efe Mon Sep 17 00:00:00 2001 From: ethers Date: Thu, 17 Nov 2016 18:14:26 -0800 Subject: [PATCH 4/5] Fallback functions don't always have to be payable --- docs/style-guide.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/style-guide.rst b/docs/style-guide.rst index 46b915e1b..eef04099b 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -173,7 +173,7 @@ Yes:: ... } - function() payable { + function() { ... } @@ -210,7 +210,7 @@ No:: ... } - function() payable { + function() { ... } From 217f33c252e8562a44c683ff1aae9de538ef475b Mon Sep 17 00:00:00 2001 From: ethers Date: Tue, 22 Nov 2016 00:47:58 -0800 Subject: [PATCH 5/5] Clearer language as suggested by @axic --- docs/style-guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/style-guide.rst b/docs/style-guide.rst index eef04099b..9aae3d7be 100644 --- a/docs/style-guide.rst +++ b/docs/style-guide.rst @@ -153,7 +153,7 @@ No:: Order of Functions ================== -Ordering helps readers identify which functions they can call, and to find the "specials" (constructor and fallback function). +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: