Code Conventions
These conventions are created by tweaking the resharper defaults so that they better fit my preferences.
- Naming
- Brace placement
- Types
- Templates
- Parentheses
- Accessibility
- Attributes
- Indents
- Blank lines
- Wrapping
- Line breaks
- Spaces
- File layout
- Commenting
All names should make clear what it resembles. The use of abbreviations or shortened versions of a word is only permitted if that version of the word is common, the name would otherwise be too long and it does not interfere with the readability of the code.
Braces should always be added. Even if it is not entirely necessary.
The first brace should always be on the same line as the function or statement. And the second one below that.
If the function or statement is empty both braces are added on the same line behind it.
An else or else if (or something similar) should have the braces like this: } else {
Always use explicit types. The only exception for this is during debugging. However, this should be removed before the feature is merged with the develop branch.
The use of templates is accepted if it makes sense for the use case of the code.
This means that the function or class must be generic in both usage and use case.
The use of redundant parentheses is only allowed if it is necessary to clarify the expression.
All variables and functions must have an explicit accessibility modifier. The accessibility must always be private unless it is either a getter/setter or a function that must be accessible by another class. For variables only constants and static variables are allowed to be public. It is allowed to make a variable protected if it has to be accessible by children of the object.
All attributes should be separated.
All code must be indented properly. Using 1 tab where the tab size is 4 spaces.
See below for a couple of examples.
Long lines of code should be wrapped so that it easily fits on the screen. Note: it is important that it is wrapped in such a way that it is still easily readable. Meaning that things that belong together should be wrapped together.
There should be spaces before and after each operator. And before the first parentheses of a statement like if.
All classes, constant variables and functions except getters and setters should be documented using doc blocks in XML format.