C++ Coding Guidelines

The following are guidelines, with explanations where needed (as some techniques may seem unorthodox to the uninitiated) to programming in C++. They are designed and derived from my work at LLNL (any many were developed by my group there prior to my joining, although I have made extensive revisions), but they should provide a good guide or starting point for work at any organization.

General:

Comments:

Class syntax

/**
 * One-line summary of the class. This is followed by a detailed overview of
 * what the class is, why it exists, how it should be used, how it fits into
 * the object structure of the rest of the design, what other classes it uses,
 * is tightly coupled to and anything else that seems relevant to understanding
 * the purpose of this class.
 */
/* Note that the above comment started with two stars after the slash. That
 * denotes that the comment provides DOC++ style comments.
 * Any notes on the implementation that are only of interest to someone
 * working on the class, and not just using the class, may be placed in a
 * normal block comment below the DOC++ comment.
 */
/* Templates should be avoided in lieu of the use of an Abstract Base Class
 * abstracting out the functionality of the classes that will be used
 * by this class. Templates should only be used if this class needs to
 * abstractly handle intrinsic types, or in the rare cases that it provides
 * a measurable and needed performance improvement.
 */
template <class Type>
class Class_One: public Class_Parent {
public:
   // Constructors
   Class_One();

   // Destructors
   ~Class_One();

   // Manipulators
   do_Something();

   // Accessors
   size();

protected:
   int inheritable;

private:
   int size_;
}; // end Class_One
    

Member Functions

Variables

Constants and macros

File format

Preprocessor and header files

Spacing

Iterators


"Zow" Terry Brugger
Last modified: Sun Jan 24 22:49:59 PST 1999