Code conventions in DDraceNetwork
This is the part 2 of my series of articles about coding in DDraceNetwork, you can find the previous one here.
What are coding conventions?
They are a set of rules that dictate how the code should be written, so that the code style is consistent among the codebase.
DDNet naming conventions
Note: There is an ongoing discussion about variable naming, find out more here.
Currently, this is how we name things:
Classes and structs
They are prefixed with
C and followed by a capital letter, like
CController, if the class is meant to be an interface it is prefixed by
They must be all screaming snake case like:
The name is divided in 3 parts: qualifier, prefix and name.
m for member variables,
s for static variables.
There is also
g for global variables with external linkage.
If, the qualifier is not empty it is followed by an underscore.
There are 2 common type prefixes:
p for pointers,
a for arrays and
fn for functions, note that you can stack the prefixes for example in the case of a pointer to a pointer.
The first letter of the variable must be uppercase.
The following snippet is very common in ddnet code:
char aBuf; str_format(aBuf, sizeof(aBuf), "number: %d", 2);
This is how we format strings, and it's used everywhere (str_format is defined in system.h).
I will add more here when I find/remember more.
More to come
- Implementing a chat command
- Implementing a rcon command
- Adding configuration options to the client.
- Modify the menus to show a label and a button/checkbox/slider for the previously added options.
- Add a new network packet.
- Add a new map tile.
- Any other idea I may get in the future.