Style Standards
- 1 Spacing
- 1.1 Indentation
- 1.2 Braces
- 1.3 Operators
- 1.4 Comments
- 2 Naming
- 2.1 Variables
- 2.2 Data Structures
- 2.3 Misc
Spacing
Indentation
Always use spaces and not tabs.
In files autogenerated by CubeIDE, use 2 spaces (CubeIDE uses 2 spaces indent on any lines it writes)
In all other files use 4 spaces
When in doubt, follow the majority indent style in a file.
Braces
Keep braces on the same line as the opening statement (class, struct, function, enum, etc).
Do this:
statement {
...
}
Do not do this:
statement
{
...
}
Add a single space between the statement and the opening brace.
Do this:
statement {
...
}
Do not do this:
Operators
Add a space on either side of operators.
Do this:
Do not do this:
Comments
Add a space between '//' and the actual comment.
Do this:
Do not do this:
Naming
Variables
Type | Style | Example |
---|---|---|
Members | Camel Case w/ Underscore | fooBar_ |
Constants | Screaming Snake Case | FOO_BAR |
Defines | Screaming Snake Case | FOO_BAR |
Others | Camel Case | fooBar |
Data Structures
Type | Style | Example |
---|---|---|
Classes | Pascal Case | FooBar |
Structs | Pascal Case | FooBar |
Enums | Pascal Case w/ Underscore 'e' | FooBar_e |
Misc
Type | Style | Example |
---|---|---|
Functions | Camel Case | fooBar |
Typedefs | Pascal Case w/ Underscore 't' | FooBar_t |
Files and Folders | Snake Case | foo_bar |