From d119c6c18817a24c1e3791704ea6a7e6e4a354a6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 13 Feb 2015 16:38:06 +0100 Subject: [PATCH] Coding standards update. --- CodingStandards.txt | 20 ++++++++++++++++++-- alethzero/MainWin.h | 3 +-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CodingStandards.txt b/CodingStandards.txt index 8acea78ae..76e1203a4 100644 --- a/CodingStandards.txt +++ b/CodingStandards.txt @@ -1,8 +1,11 @@ 0. Formatting +GOLDEN RULE: Never *ever* use spaces for formatting. + a. Use tabs for indentation! - tab stops are every 4 characters. - One indentation level -> exactly one byte (i.e. a tab character) in the source file. +- Never use spaces to line up sequential lines: If you have run-on lines, indent as you would for a block. b. Line widths: - Don't worry about having lines of code > 80-char wide. - Lines of comments should be formatted according to ease of viewing, but simplicity is to be prefered over beauty. @@ -17,10 +20,22 @@ j. Braces, when used, always have their own lines and are at same indentation le (WRONG) if( a==b[ i ] ) { printf ("Hello\n"); } +foo->bar(someLongVariableName, + anotherLongVariableName, + anotherLongVariableName, + anotherLongVariableName, + anotherLongVariableName); (RIGHT) if (a == b[i]) - printf("Hello\n"); // NOTE spaces used instead of tab here for clarify - first byte should be '\t'. + printf("Hello\n"); // NOTE spaces used instead of tab here for clarity - first byte should be '\t'. +foo->bar( + someLongVariableName, + anotherLongVariableName, + anotherLongVariableName, + anotherLongVariableName, + anotherLongVariableName +); @@ -98,7 +113,7 @@ g. Never use a macro where adequate non-preprocessor C++ can be written. h. Prefer "using NewType = OldType" to "typedef OldType NewType". i. Make use of auto whenever type is clear or unimportant: - Always avoid doubly-stating the type. -- Use to avoid vast and unimportant type declarations +- Use to avoid vast and unimportant type declarations. (WRONG) @@ -173,6 +188,7 @@ d. In general expressions should be roughly as important/semantically meaningful a. Comments should be doxygen-compilable, using @notation rather than \notation. + 12. Include Headers a. Includes should go in order of lower level (STL -> boost -> libdevcore -> libdevcrypto -> libethcore -> libethereum) to higher level. Lower levels are basically dependencies to the higher levels. For example: diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 4e21d493f..2625f566d 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -239,8 +239,7 @@ private: /// Attempts to infer that @c _source contains Solidity code bool sourceIsSolidity(std::string const& _source); /// @eturns all method hashes of a Solidity contract in a string - std::string const getFunctionHashes(dev::solidity::CompilerStack const &_compiler, - std::string const& _contractName = ""); + std::string const getFunctionHashes(dev::solidity::CompilerStack const &_compiler, std::string const& _contractName = ""); std::unique_ptr ui;