EECS 230: C++ Style Manual

  1. Names

    1. Member variable names are appropriately descriptive of what they stand for; names shouldn’t just reiterate the type.
    2. Variable and function names start with a lowercase letter.
    3. Class and struct names start with an uppercase letter.
    4. Type alias names may be initial uppercase, or initial lowercase ending in _t.
  2. Variables

    1. Variables are initialized when defined if possible.
    2. Variables are defined in the narrowest possible scope.
  3. Formatting

    1. Lines are no longer than 80 characters.
    2. Indentation is consistent and properly reflects code structure.
    3. Indentation is by two or preferably four spaces; tabs are unacceptable because they do not display the same everywhere.
    4. Long blocks of code are separated into “paragraphs” using blank lines.
    5. Infix operators generally have space on both sides.
    6. Commas and semicolons have a space after but no space before.
  4. Comments

    1. Each top-level definition (function, struct, class) has a header comment succinctly stating its purpose.
    2. Excessive comments that inhibit readability are avoided. Assume your reader understands the language; only explain the non-obvious.
  5. Class Design

    1. Constructors ensure that every object is properly initialized.
    2. Every member is protected by the strictest level of privacy that will work for it.
    3. Getters and setters are only provided where necessary, and not where they break abstraction.