CS 311 Spring 2008  >  Coding Standards

CS 311 Spring 2008
Coding Standards

The following standards must be followed on all source code (including header files) turned in as CS 311 assignments.

1. High Quality Code

Code must be of high quality. In particular:

  1. Code must compile and execute.
  2. Code should be neat and readable, with proper indentation and use of whitespace.
  3. Code should include explanatory comments, as appropriate.
  4. Code should not perform any actions visible to the client or the user, other than those in its specification.
  5. Unnecessary or duplicate code should be avoided. In particular, in C++:
  6. All functions should pass their parameters and return values in appropriate ways, and all overloaded operators should be in the correct place (member or global).
  7. Appropriate use should be made of language constructs that deny privileges (const, private, etc.).

2. Specific Standards

  1. All source code must be in C++, as close as possible to the ANSI standard.
  2. At the beginning of every file should be a comment indicating the file’s name, author, date, and purpose.
  3. Before every function definition, except possibly main, there should be comments indicating preconditions and postconditions. Class invariants do not need to be in these lists. If a function has no preconditions (or postconditions) then write “None”.
  4. Before every class definition there must be comments indicating class invariants.
  5. Header and source files must be handled properly and in line with standard conventions, with #include in the proper places, and #ifndef to avoid multiple inclusion.
  6. Only required headers should be included, and namespace pollution should be avoided.

3. Additional Standards

In addition, some assignments later in the class will need to meet the following standards. Students will be notified when these standards must be met.

  1. Requirements on template parameter types must be documented.
  2. Exceptions thrown by each function must be documented.
  3. Exception safety levels offered by each function must be documented.


CS 311 Spring 2008: Coding Standards / Updated: 30 Jan 2008 / Glenn G. Chappell / ffggc@uaf.edu Valid HTML 4.01!