StyleGuide

From ProjectFreedom

Jump to: navigation, search

Contents

File Layout

Headers

Header files should be lain out in the following format.

#includes
#defines

structs and classes

function prototypes

inline functions (if any)

Inline functions can be written either in the class definition or after the class definition.

Source Files

#includes
#defines

structs and classes

static function prototypes

static and global variables

functions

Indenting

After every brace, start a new line and indent three more spaces. Note the exception in source files.

Header Files

In header files, braces after namespaces are to be indented, eg.

namespace Foo {
   class Bar {
      public:

      Bar();

      void f();

      void inlineFun() {
         int x;
         std::cout << "I'm inline" << std::endl;
      }
   };
}

Source Files

Don't indent after "namespace", even if there are multiple levels of nested namespaces.

If you break a long function prototype into multiple lines then indent the lines after the first one, eg.

int foo(int x, int y,
        int z) {
}

Naming

All names are to be mixed case with lower case as the first letter for variables and functions, and upper case for namespace names, class and struct names, typedefs and enums, eg.

typedef std::string String
class Foo {
   //class body
};

Language Construct Layout

if and while are to be written with the opening brace on the same line, eg.

if (true) {
}

Miscellaneous

Never use "using namespace std", always use std:: to reference things in the std namespace.

Typedef templates for clarity, eg. typedef std::set<std::string> EntityNames;

Never use single statement if or while, always use braces.

If developing for the engine, everything is to be within the namespace PFreedom.

Personal tools