1.5 KiB
1.5 KiB
These are more like guidelines
Naming schemes
- Use reasonable names, especially for class members
- Use shortened names for local variables
- Use comments to explain if a name doesn't obviously imply what the variable does
Constants and types
- All constant variables should be in all CAPS
- When not needing values to distinguish flags (i.e. the flag is only there to denote a type, its value can be anything), use enum.
- If a template object is used more than once, it is a good idea to wrap it in a class/struct or use a typedef
- If the purpose of a class is solely to store data, use a struct.
Object design
- If an object isn't meant to be inherited, declare it final
- If a member function has to be implemented individually, declare it as a pure virtual function.
Global variables
- Avoid using global variables at all costs
- Can improve rng to be referenced instead of externally exported
Functions and local variables
- A function should be at most 40 lines unless it's logically simple (e.g. has a long switch statement that calls other functions). rationale: functions should be short and sweet and let the people reading them know what it does.
- Never have more than 4 local variables in the scope of a function at the same time. rationale: a normal human's brain can only keep track of a handful of things at once
STL library
- Prefer using the STL library over raw data types unless it's a very simple data type
- Use unique_ptr<> for heap-allocated objects