• Immutable Page
  • Info
  • Attachments

Basic style

  • Separate words in functions and variables with CamelCaps. Do not use underscores for new variables, unless there is some macro in an external lib which requires it.

  • Indentations are 4 spaces wide, tabs are eight. So odd-leveled indentation ends with 4 spaces. In other words: For one level of indentation you use 4 spaces. For two levels you use 1 tab, for three levels you use one tab and 4 spaces, for four levels you use two tabs, and so on.
  • Function calls have a space between name and parameters:

    foo ()

    not

    foo()
  • Braces/brackets fall on next line to assist readability and closure detection:

    if (foo)
    {
        bar ();
    }
    else 
    {
        baz ();
    }

    not

    if (foo) {
       bar ();
    } else {
       baz ();
    } 
  • It's ok, though, to omit the braces for a single line call:

    if (foo)
        bar ();
    
    bla();
  • Function specs/prototypes have return and name/parms on seperate lines. Params should be aligned:

    static int
    foo (int          a,
         unsigned int b)
    {
       bar (a, b);
    }

    not

    static int foo (int a, unsigned int b)
    {
       bar ();
    }
  • We use C comments, not C++ ones:

    /* this calls foo if bar */
    if (bar)
        foo ();

    not

    // this calls foo if bar
    if (bar)
        foo ();
  • Variables are defined at the beginning of the scope.
  • Rule of thumb: CompScreen are called s and CompWindow ones w. As usual, there may be exceptions (e.g. if one needs multiple CompWindow variables).

  • All member and global variables must be prefixed:

    int gBaz;
    
    class Foo
    {
        public:
    
            int mBar;
    }

    This is to avoid confusion as to which variables are in what scope, which can lead to nasty cases of variable shadowing

Editor settings

vim

set formatoptions=croqlt
set ts=8
set softtabstop=4
set shiftwidth=4
set cindent
set tw=80
set cino=(0,t0

Development/CodingStyle (last edited 2010-09-27 09:30:24 by 124-169-58-87)