Coding Style Guide for C++ programming

(Created by Vangelis Metsis, Roger Priebe, J. Slomka)

In addition to working correctly, programs should be readable and maintainable.  Studies have shown that for large software projects, the cost of writing a program is significantly less than the cost of maintaining it over its lifespan.  Therefore, writing code using a clear and consistent style is economically critical.

There are many different 'good' styles for coding in C++, and  a consistent style is probably more important than the particular style used.  Most large programming groups will have a style manual that must be followed by all programmers.

This document describes the style conventions expected to be used in my CS 3358 course.  In some cases I present options for the students to use, in other cases I specify a precise style.  This document is not complete - it is very possible to follow it and still write poorly styled code. ( If you are determined to write lousy C or C++ code, consider entering The International Obfuscated C Code Contest rather than doing it in this course  ).

File layout and documentation

Header Files

Indentation & Spacing

You must choose 1 style for braces and use it consistently.

Names

Declarations

Note: If your variable names are descriptive (and they better be), you may not need a comment after each one.

Note: I prefer one declaration per line with the type, but will allow variables to be declared as shown above.

Constants

Local Variables

Structs vs. Classes

Functions

Use of const

Comments