Skip to main content

Unify Your Code

We use clang with autoformatting and code-completion to help us normalize our codes. This improves overall code readability not only for you, but for others reading your code.

CLANG-FORMAT

Make sure to have it in the root of your repository, formatters look from the inside-out in the current directory for the format specifications, so that it is applied to all your codes.

clang-format can be easily integrated into your IDE (e.g., VSCode, Vim, etc.) to automatically format your code on save or on demand. This ensures that all your code adheres to the same style guidelines without requiring manual effort.

Checkout Code EditorTips to see how to set clang up.


Clang-Format Configuration

Download or copy our .clang-format file:

.clang-format

---
Language: Cpp
Standard: c++20

AccessModifierOffset: -2
ColumnLimit: 160
MaxEmptyLinesToKeep: 2

AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true

AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false

AlwaysBreakTemplateDeclarations: true
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma

IndentCaseLabels: true
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
SortIncludes: false
SpaceBeforeParens: ControlStatements

BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: true
AfterFunction: false
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: false
IndentBraces: false
...