Coding Style


The coding style should be fairly easy to pick up when looking at the source files. But here are some pointers:

  • Indent with tabs, with 4 character tab stops.
  • Bracing style (Use braces, even if it is a single statement):
  • Function(), if(), switch(), etc... no space before the brackets.
  • Code is split up into logical groups in the lib/* directories, although the use of these is minimised.


  • Variable names are prefixed with m (class member), p (pointer), r (reference) in that order. Arguments to functions are capitalised (ArgumentToFunction, rArgumentToFunction), local variables aren't (localVariable). Member variables are caplitalised too, but always start with m.
  • Classes are ClassName (with no prefix), and member functions are FunctionName?(). Code lives in .cpp and .h files with the same name as the class.
  • Non-member function calls are prefixed with ::, eg ::printf(...).

Language features

  • #include "Box.h" must be the first include in every cpp file. On some platforms, failing to do this absolutely first will cause the compiled code to crash due to inconsistent options.
  • Prefer references to pointers.
  • Exceptions are used. All are autogenerated, and thrown with the THROW_EXCEPTION macro. Except for std::bad_alloc, which is thrown when memory allocations failed.
  • Objects are allocated on the stack whereever possible to ease exception handling.
  • No overloading of operators, especially not for i/o. Only exception is comparison operators, but even then, only if really justified. (Justification: it is not obvious what an operator will do!)
  • Use the STL wherever useful, but don't use the STL style! (ie. the lower case names and underscores)
  • If a function returns a newly allocated object, use an std::auto_ptr<> to return it. Do not use std::auto_ptr<> as the type for a parameter in method declarations.
  • There is no global base class.
  • Serialisation is done using two functions:
    void ReadFromStream(IOStream &rStream, int Timeout);
    void WriteToStream(IOStream &rStream) const;
  • Serialisable objects are not derived from any particular base class as it doesn't seem necessary. Templates can be used if generic code is necessary.
  • All serialised objects use network byte order.
Last modified 12 years ago Last modified on Nov 23, 2006, 10:22:36 PM