id Software C++ Coding Conventions

id Software - John Carmark



I found this interesting 7-page paper that explains id Software C++ coding conventions. I think every serious software development company should have such a paper and show it to new programmers. To make your life easier, Geeks3D offers you id Software Coding conventions in a PDF file you can download right here:
[download#23#image]

7 thoughts on “id Software C++ Coding Conventions”

  1. Hightree

    Thanks a bundle !
    This will make a great template for our own coding conventions doc.

  2. saew

    I think ID has very few experience with C++. They used C a loooong time and they started to program their games using C++ just a few years ( for Quake Wars I think ).

    I’m programming C++ for 10 years and that doc clearly shows some immature decisions, for example:

    if ( x ) {
    blah valh
    }else {
    }

    that’s ugly notation that does not help at all the code readability and neither correct code identation. It’s way better this other one:

    if ( x )
    {
    //blah blah
    }
    else
    {
    //blah blah
    }

    ( which is called ANSI C++ style brackets btw ).

    Other thing I don’t like is that pseudo-hungary notation with the _t at the end

    struct myStruct_t

    almost all the code editors in the world ( VS, NetBeans, Eclipse, SlickEdit, etc etc ) can tell you if a data structure is a struct, a class, an integer, etc in the debug watch, class navigators, etc… actually, I think there is no need at all to use hungary notation and neither that 80-era _t thing.

    They’s are using “float” also which is terribly bad. A good practise is to re-map floating point types to custom typedefs or classes, so you can alter the type them easy. For example, imagine you’re developing a mobile game and that platform does not suppport floats… with custom classes or a typedef you can use fixed fp precision or whatever…

  3. JeGX Post Author

    Totally OK with you. Thanks for your contribution saew, interesting reading 😉

    The convention

    if ( x ) {
    blah valh
    }else {
    }

    is awful and I prefer a more compact manner like this:
    if (x)
    {
    doSomething1();
    doSomething2();
    }
    else
    {
    doSomething3();
    doSomething4();
    }

    or

    if (x)
    doSomething1();
    else
    doSomething2();

    But I appreciate the fact id Software has a coding convention paper and this is a good example to follow with of course, each one with his own conventions!

  4. Philip Spencer

    Nice to see someone’s best practice recommendations. I’ve been coding in flavours of C for over 20 years, and would support ID’s layout choice regarding braces:
    if ( x ) {
    blah valh;
    } else {
    vlah balh;
    }

    for two primary reasons:

    1: Safety in code maintenance. Many times I have seen the alternate format accidentally split, changing the code flow but not generating compile warnings:
    if ( x )
    {
    blah blah;
    }
    else
    line added during maintenance;
    {
    blah blah;
    }

    or the simple case
    if ( x )
    line added during maintenance;
    {
    blah blah;
    }

    The most common instance is the accidental
    for ( ix = 0; ix < END_IX; ix++ );
    {
    copy[ix] = original[ix];
    }

    Legal code and hard to spot, but not what is intended.

    2: Compact presentation. Either on an old-fashioned glass teletype screen, or in a typical small window in a GUI environment, one is often performing keyhole surgery on the source code, and this format maximises the quantity of functional code visible.

    I also like the way that the closing brace matches the start conditional (or function, or loop control, etc), and the clearer indentation (IMHO).

  5. Jason McGuiness

    Might I suggest a more modern, and comprehensive work upon which one may base their coding standards? (That is also peer-reviewed.) My suggestion is:

    “C++ Coding Standards” by H. Sutter et al, Addison-Wesley, Feb 2005.

  6. Andreas

    Guys, it’s not about the particular choice of conventions id uses. The point is to have such a paper, and make it available to every developer.

Comments are closed.