-
Notifications
You must be signed in to change notification settings - Fork 6
StyleGuide
Even though the original code may not have the best (or very consistent) style here are some rules for new or modified code:
-
The indentation length is two spaces. No tab characters are allowed. (Two spaces is usually what C mode in Emacs defaults to.) The original code was using tabs heavily and tabs were rendered as three spaces.
-
Code blocks after if/for/while/etc statements should always be surrounded by { }, even if it's only one statement.
-
Try keeping lines shorter than 80 characters.
-
The opening brace for a method/if/for/while/etc should be on the same line, not on its own on the line below.
-
Function names should generally be camelCase. Functions that are local to a module (C source file) should start with a lower case character. Functions that are exported and library functions should start with a upper case character.
-
Functions that implement a NiKom command should start with "Cmd_". E.g. "Cmd_ChangeUser()".
-
There should normally be spaces between operators and operands. I.e.
foo = 2 + 3
and notfoo=2+3
. There should also normally be spaces after commas and semicolons. I.e.foo(1, 2)
and notfoo(1,2)
andfor(i = 0; i < 10; i++)
and notfor(i = 0;i < 10;i++)
. -
Avoid treating integers like booleans. If you want to check whether an integer is 0 then prefer
foo == 0
over!foo
. Also for characters preferch == '\0'
overch == 0
or!ch
. On the other hand if the variable is functionally a boolean thenif(!userIsAwesome)
is preferred. -
Iteration counters should be called i, j etc and not x, y etc. I.e.
for(i = 0; i < 10; i++)
and notfor(x = 0; x < 10; x++)