Changes between Version 2 and Version 3 of CodingGuidelines
- Timestamp:
- 10/31/10 18:00:50 (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CodingGuidelines
v2 v3 38 38 Also, write modern C code. Include parenthesis wherever it increases readability, and nowhere else. Always declare functions as <type> <name>(<params>). If you don't pass any parameters, make sure you write 'void' in the declaration. Use the 'const' wherever you don't modify a variable. 39 39 40 Write code for humans first and execution second. Where code is unclear, comment, but there is no need to write such as the following:40 Write code for humans first and execution second. Where code is unclear, comment, but e.g. the following is unneccessarily verbose and hurts readability: 41 41 {{{ 42 42 /* Delete the object */ 43 43 object_delete(idx); 44 44 }}} 45 It is unneccessarily verbose and hurts readability. Group code instead into ideas and comment each section of ideas. Also, use whitespace liberally to separate ideas visually.46 45 47 46 Each function should have a comment at its head, describing the function and including any notes on its usage, including what its various return values (if any) mean. Avoid multi-line comments in functions; instead, split the code that requires the comments into its own function or move the comment into the comment section at the top of the function. … … 51 50 If you make use of memory allocation in your module, try and make such code clean up after itself, or include it in "init" and "free" functions. Always initialise your module so it is in a known state! It is possible that the game will eventually not quit when you lose a character, but rather allow another character to be loaded or created. Unless you get things in a known state, this will cause crashes. 52 51 53 Don't use magic numbers. Use defines or enums (and enums where possible). Where a constant is local, include it at the top of a file/section. Where it is not, place it in the module's corresponding header file. Avoid putting more things into defines.h .52 Don't use magic numbers. Use defines or enums (and enums where possible). Where a constant is local, include it at the top of a file/section. Where it is not, place it in the module's corresponding header file. Avoid putting more things into defines.h/externs.h. 54 53 55 54 Don't use floating point calculations.