Copied and modified from Google Filament code style. Remember: break the rules if it makes sense, e.g. it improves readability substantially.
- 4 spaces indent
- 8 spaces continuation indent
- 100 columns
{at the beginning of new line- spaces around operators, and after
;in loop conditions - class access modifiers are not indented
- third party source code may use the formatting of their own
for (int i = 0; i < max; ++i)
{
}
class Foo
{
public:
protected:
private:
};
- headers use the
.hextension - implementation files use the
.cppextension - included files use the
.inlineextension - no spaces in file names
- use
#include < >for all public (exported) headers - use
#include " "for private headers - tests reside under the
testsfolder - public headers of a
foolibrary must live in a folder namedfoo
include/foo/FooBar.h
src/FooBar.cpp
src/data.inc
#include <foo/FooBar.h>
#include "FooBarPrivate.h"
- Everything is camel-cased except constants
constantsare upper-cased and don't have a prefixglobalvariables prefix withg_staticvariables and class attributes prefix withs_privateandprotectedclass attributes prefixed with_publicclass attributes prefix with_or not prefixed- class names are upper camel-cased
- all variables, class attributes and methods are lower camel-cased
extern int g_globalWarming;
const int FOO_COUNT = 10;
class FooBar
{
public:
void methodName(int arg1, bool arg2);
int sizeInBytes;
private:
int _attributeName;
static int s_globalAttribute;
enum { ONE, TWO, THREE };
};
- When using STL, always include the
std::qualifier to disambiguate it from others.