Changes between Version 2 and Version 3 of CodingStyle


Ignore:
Timestamp:
Dec 22, 2007, 5:21:09 PM (17 years ago)
Author:
Nicolas
Comment:

Minor cleanup

Legend:

Unmodified
Added
Removed
Modified
  • CodingStyle

    v2 v3  
    11= BOINC coding style =
    22
    3 ==  All languages ==
     3== All languages ==
    44
    5 ===  Code factoring ===
     5=== Code factoring ===
    66
    7  * If code is repeated, factor it out and make it into a function
    8  * If a function becomes longer than 100 lines or so, split it up
     7 * If code is repeated, factor it out and make it into a function.
     8 * If a function becomes longer than 100 lines or so, split it up.
    99 * If a file is becoming 'landfill', split it up.
    10  * C++ .h files often contain both interface and implementation.         Clearly divide these.
     10 * C++ .h files often contain both interface and implementation. Clearly divide these.
    1111
    12 ===  Code documentation ===
     12=== Code documentation ===
    1313
    1414 * .C files have a comment at the top saying what's in the file (and perhaps what isn't).
     
    1616 * Structs and classes are preceded by a comment saying what they are.
    1717
    18 ===  Naming ===
     18=== Naming ===
    1919
    20  * Names should be descriptive without being verbose (local variables names may be short)
    21  * Class and type names, and #defined symbols, are all upper case,         with underscores to separate words.
     20 * Names should be descriptive without being verbose (local variables names may be short).
     21 * Class and type names, and #defined symbols, are all upper case, with underscores to separate words.
    2222 * Variable and function names are all lower case, with underscores to separate words.
    23  * No mixed case names
     23 * No mixed case names.
    2424
    2525=== Indentation ===
    2626
    2727 * Each level of indentation is 4 spaces (not a tab).
    28  * multi-line function call:
     28 * Multi-line function call:
    2929{{{
    3030func(
     
    3333);
    3434}}}
    35  * switch statements: case labels are at same indent level as switch
     35 * {{{switch}}} statements: {{{case}}} labels are at same indent level as {{{}}}switch:
    3636{{{
    3737switch (foo) {
     
    6161}
    6262}}}
    63  * always use curly braces on multi-line if statements
     63 * Always use curly braces on multi-line `if` statements.
    6464{{{
    6565if (foo)
    6666    return blah;     // WRONG
    6767}}}
    68  * 1-line if() statments are OK:
     68 * 1-line `if()` statements are OK:
    6969{{{
    7070if (foo) return blah;
     
    8686=== Includes ===
    8787
    88  * A .C file should have the minimum set of #includes to get that particular file to compile (e.g. the includes needed by foo.C should be in foo.C, not foo.h)
    89  * Includes should go from general (<stdio.h>) to specific (thisfile.h)
     88 * A .C file should have the minimum set of #includes to get that particular file to compile (e.g. the includes needed by {{{foo.C}}} should be in {{{foo.C}}}, not {{{foo.h}}}).
     89 * Includes should be ordered from general (`<stdio.h>`) to specific (`thisfile.h`).
    9090
    9191=== Extern declarations ===
    9292
    93 foo.h should have 'extern' declarations for all public functions and variables in foo.C There should be no 'extern' statements in .C files.
     93{{{foo.h}}} should have '{{{extern}}}' declarations for all public functions and variables in {{{foo.C}}} There should be no '{{{extern}}}' statements in {{{.C}}} files.
    9494
    9595=== Use of static ===
    9696
    97  * if a function or variable is used in only one file, declare it static.
     97 * If a function or variable is used in only one file, declare it {{{static}}}.
    9898
    9999=== Things to avoid unless there's a truly compelling reason: ===
    100100
    101  * inline functions
    102  * operator or function overloading
    103  * templates
     101 * Inline functions.
     102 * Operator or function overloading.
     103 * Templates.
    104104
    105105=== Things to avoid ===
    106106
    107  * use typedef (not #define) to define types
    108  * don't use memset() or memcpy() to initialize or copy classes        that are non-C compatible. Write a default constructor and a copy constructor.
     107 * Use {{{typedef}}} (not {{{#define}}}) to define types.
     108 * Don't use {{{memset()}}} or {{{memcpy()}}} to initialize or copy classes that are non-C compatible. Write a default constructor and a copy constructor.
    109109
    110110=== Error codes ===
    111111
    112  * (almost) all functions should return an integer error code.        Nonzero means error. See lib/errornumbers.h for a list of error codes.
     112 * (Almost) all functions should return an integer error code. Nonzero means error. See lib/errornumbers.h for a list of error codes.
    113113 * Calls to functions that return an error code should check the code. Generally they should return on error, e.g.:
    114114{{{