Whitespace
- Use two spaces for indentation. This makes for less wasted space and shorter lines.
- Tabs are not allowed. This ensures that indentation remains consistent.
- Don't leave trailing spaces.
- Use one space after language keywords to distinguish them from function calls.
- Use one space after commas, but not before. This is easier to read.
- Use one space before and after operators. This is easier to read.
- End files with a newline.
Code style
- Put opening braces at the end of the line that creates the block, preceded by a space. This allows for more viewable lines of code at once.
- Put closing braces on their own line, indented at the same level as the line that created the block.
- Always use braces for code blocks, even if the block consists of only one line. This is more clear and future-proof.
- Put
else
on its own line, preceding a block. This is more clear.
Function and variable naming
- Use CamelCase for class names, struct names, and enumeration values.
- Use lowerCamelCase for constants and variable names.
Prefixes
There are two types of prefixes, which can be used in conjunction. They make code easier to understand and use, and help with code autocompletion. These are scope prefixes and usage prefixes.
Scope prefixes
Scope prefixes consist of one character and are followed by an underscore.
You must use the following prefixes:
- a
- function argument/parameter
- m
- (non-static) class member
Usage prefixes
Usage prefixes consist of one or more characters and follow the scope prefix, if present.
You must use the following prefixes:
- i
- index (of for loops, arrays, and objects that use the subscript ([]) operator in the same way)
- k
- constant
- n
- amount of something
- p
- pointer
- pp
- pointer to pointer
Examples
m_x
- A member variable named x.
a_pSprite
- A function argument parameter that is a pointer to a sprite.
knBitmaps
- A constant of an amount of bitmaps.