Changes between Version 2 and Version 3 of CodingGuidelines


Ignore:
Timestamp:
10/31/10 18:00:50 (8 years ago)
Author:
takkaria
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CodingGuidelines

    v2 v3  
    3838Also, 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. 
    3939 
    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: 
     40Write code for humans first and execution second. Where code is unclear, comment, but e.g. the following is unneccessarily verbose and hurts readability: 
    4141{{{ 
    4242    /* Delete the object */ 
    4343    object_delete(idx); 
    4444}}} 
    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. 
    4645 
    4746Each 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. 
     
    5150If 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. 
    5251 
    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. 
     52Don'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. 
    5453 
    5554Don't use floating point calculations.