mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Update coding style and add .clang-format
This commit is contained in:
parent
f9de17ec2f
commit
2887bffcfd
@ -1,29 +1,17 @@
|
|||||||
Coding
|
Coding
|
||||||
====================
|
====================
|
||||||
|
|
||||||
Please be consistent with the existing coding style.
|
Various coding styles have been used during the history of the codebase,
|
||||||
|
and the result is not very consistent. However, we're now trying to converge to
|
||||||
Block style:
|
a single style, so please use it in new code. Old code will be converted
|
||||||
```c++
|
gradually.
|
||||||
bool Function(char* psz, int n)
|
- Basic rules specified in src/.clang-format. Use a recent clang-format-3.5 to format automatically.
|
||||||
{
|
- Braces on new lines for namespaces, classes, functions, methods.
|
||||||
// Comment summarising what this section of code does
|
- Braces on the same line for everything else.
|
||||||
for (int i = 0; i < n; i++)
|
- 4 space indentation (no tabs) for every block except namespaces.
|
||||||
{
|
- No indentation for public/protected/private or for namespaces.
|
||||||
// When something fails, return early
|
- No extra spaces inside parenthesis; don't do ( this )
|
||||||
if (!Something())
|
- No space after function names; one space after if, for and while.
|
||||||
return false;
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success return is usually at the end
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- ANSI/Allman block style
|
|
||||||
- 4 space indenting, no tabs
|
|
||||||
- No extra spaces inside parenthesis; please don't do ( this )
|
|
||||||
- No space after function names, one space after if, for and while
|
|
||||||
- Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp):
|
- Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp):
|
||||||
```c++
|
```c++
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
@ -38,31 +26,29 @@ Block style:
|
|||||||
class CAlpha;
|
class CAlpha;
|
||||||
class CBeta;
|
class CBeta;
|
||||||
```
|
```
|
||||||
- When using namespace keyword use the following form:
|
|
||||||
|
Block style example:
|
||||||
```c++
|
```c++
|
||||||
namespace Foo {
|
namespace foo
|
||||||
|
{
|
||||||
|
class Class
|
||||||
|
{
|
||||||
|
bool Function(char* psz, int n)
|
||||||
|
{
|
||||||
|
// Comment summarising what this section of code does
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
// When something fails, return early
|
||||||
|
if (!Something())
|
||||||
|
return false;
|
||||||
...
|
...
|
||||||
|
}
|
||||||
|
|
||||||
} // Foo
|
// Success return is usually at the end
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
Variable names begin with the type in lowercase, like nSomeVariable.
|
|
||||||
Please don't put the first word of the variable name in lowercase like
|
|
||||||
someVariable.
|
|
||||||
|
|
||||||
Common types:
|
|
||||||
|
|
||||||
n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number
|
|
||||||
d double, float
|
|
||||||
f flag
|
|
||||||
hash uint256
|
|
||||||
p pointer or array, one p for each level of indirection
|
|
||||||
psz pointer to null terminated string
|
|
||||||
str string object
|
|
||||||
v vector or similar list objects
|
|
||||||
map map or multimap
|
|
||||||
set set or multiset
|
|
||||||
bn CBigNum
|
|
||||||
|
|
||||||
Doxygen comments
|
Doxygen comments
|
||||||
-----------------
|
-----------------
|
||||||
|
51
src/.clang-format
Normal file
51
src/.clang-format
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignEscapedNewlinesLeft: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
BinPackParameters: false
|
||||||
|
BreakBeforeBinaryOperators: false
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
ColumnLimit: 0
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, BOOST_REVERSE_FOREACH ]
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentFunctionDeclarationAfterType: false
|
||||||
|
IndentWidth: 4
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
Language: Cpp
|
||||||
|
MaxEmptyLinesToKeep: 2
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: false
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PointerAlignment: Left
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
Standard: Cpp03
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
Loading…
Reference in New Issue
Block a user