Skip to content
Niklas Lindholm edited this page Apr 21, 2017 · 5 revisions

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 not foo=2+3. There should also normally be spaces after commas and semicolons. I.e. foo(1, 2) and not foo(1,2) and for(i = 0; i < 10; i++) and not for(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 prefer ch == '\0' over ch == 0 or !ch. On the other hand if the variable is functionally a boolean then if(!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 not for(x = 0; x < 10; x++)

Clone this wiki locally