Code Style Guide

Jules Milner-Brage & Jeff Walker

Naming:

Do not use 'A' or 'I' as a prefix to an abstract class or interface. Proper names can imply when something is abstract. Also, interface does not always have meaning in a language. When using a pattern consider using the pattern name in the class in addition to a meaningful root name. A class' role in a pattern may also make a useful name part.

Header files will always have .h extensions and be in a directory reflecting their nesting in modules. System headers are for things considered so important that you directly use their name. In this case a header is generated without a .h and it includes the one with the .h. If multiple system headers would have the same name (i.e. vector) then including the name includes all classes with that name. Since they are in different modules no conflicts occur and using directives should be used to select the desired implementation.

Preprocessor:

#ifndef headerFileName_h_
#define headerFileName_h_

// include directives

// header file contents

#endif // headerFileName_h_

Comments:

Spacing:

class ClassName: public SuperName
{
private: static ClassName *instance;
public: ClassName()
ClassName(int x): property(x) { }

virtual void method1(Type &param, Type2 param2) = 0;
virtual void method2(Type &param, Type2 param2);
};

ClassName::ClassName(): property(8),
foo(7)
{ }

void ClassName::method2(Type &param, Type2 param2)
{if()
{ }
}

Code:



1  may be used in a parameterized form <type variable>specialization (e.g. τVisitor).

jwalker@cs.oberlin.edu