Programming style

Programming style#

Python style#

We follow the PEP8 style guide and use yapf and flake8 to format the code. We have the following setting in setup.cfg:

[yapf]
based_on_style = google
allow_split_before_dict_value = False
[flake8]
max-line-length = 80

C++ style#

The C++ code should be formatted using clang-format. We have the following setting in .clang-format:

---
BasedOnStyle: Google
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
  IndentBraces:    false
  AfterNamespace:  false
  AfterClass:      true
  AfterFunction:   true
  AfterEnum:       true
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     true
  BeforeElse:      true
  AfterControlStatement: true
  SplitEmptyFunction:    true
  SplitEmptyRecord:      true
  SplitEmptyNamespace:   true
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma
ColumnLimit: 150
Cpp11BracedListStyle: true
DerivePointerAlignment: true
IndentWidth: 4
Language: Cpp
PointerAlignment: Left
Standard: Cpp11
TabWidth: 4
UseTab: Never
FixNamespaceComments: true

...