Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 13 and Version 14 of code/C++_styleguide


Ignore:
Timestamp:
Apr 14, 2008, 5:05:06 PM (16 years ago)
Author:
rgrieder
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/C++_styleguide

    v13 v14  
    99
    1010== Files ==
    11 === Header and Source ===
    12 Keep your classes/files short, don't exceed 2000 LOC (if it get's longer you may separate functions into different modules). Put every class in a separate file and name the file like the class name (use !CamelCase names). Create a separate header (ends with .h) and source file (ends with .cc) and don't include header files in header files but rather in source files if you can help it. Example for class {{{MyExampleClass}}}.
     11=== General ===
     12Keep your classes/files short, don't exceed 2000 LOC (if it get's longer you may separate functions into different modules). Put every class in a separate file and name the file like the class name (use !CamelCase names). Create a separate header (ends with .h) and source file (ends with .cc).
     13 and don't include header files in header files but rather in source files if you can help it.
     14Example for class {{{MyExampleClass}}}.
    1315{{{
    1416file names:
    1517MyExampleClass.cc
    1618MyExampleClass.h
     19}}}
     20
     21=== Headers ===
     22Keep your include dependencies in header files as little as possible. Whenever a class member is just a pointer or reference, the forward declaration is sufficient. To make that easier there exists a prerequisites file for each library, containing all the necessary forward declarations. These have to be kept up to date of course.
     23Example for a header file include sequence.
     24{{{
     25#include "MyLibraryPrereqs.h"
     26
     27#include <string>              // std includes
     28
     29#include <OgrePrerequisites.h> // most external libraries have forward declaration files as well
     30#include <OgreFrameListener.h> // only include this if you inherit from it or you don't use an object as pointer/reference
     31
     32#include "Projectile.h"        // our own files, if necessary
     33}}}
     34Note: Never ever (!!!) write {{{using namespace blah;}}} in header files! (think about what it means a little bit)
     35
     36=== Source files ===
     37Again, keep the dependencies short. However it is not that severe in source files.[br]
     38To ensure that every header file can be compiled without additional header dependencies, include class header file first.
     39Include sequence is for {{{MyClass}}}:
     40{{{
     41#include "MyClass.h"
     42
     43#include <vector>              // std headers
     44#include <map>
     45
     46#include <OgreSceneManager.h>  // external library headers
     47
     48#include "BaseObject.h"        // our own header files
    1749}}}
    1850