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:
- Code must compile and execute.
- If the code is not a complete program, then this standard means that the code will
compile and execute with any correct program that uses it.
In particular, if a test program is given, then the turned in code must compile and execute with the test program.
- Programs that fail to meet this standard will generally not be graded.
- Code should be neat and readable,
with proper indentation and use of whitespace.
- Code should include explanatory comments, as appropriate.
- Code should not perform any actions visible to the client or the user,
other than those in its specification.
- In particular, avoid debugging printout in the turned-in version of your code.
- Unnecessary or duplicate code should be avoided. In particular, in C++:
- Silently written member functions must be used whenever possible.
When they are used, the fact must be noted in a comment.
- In a constructor, initializers should be used appropriately.
- 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).
- Appropriate use should be made of language constructs that deny privileges (const, private, etc.).
- It is worth some extra time to get this right!
2. Specific Standards
- All source code must be in C++, as close as possible to the ANSI standard.
- At the beginning of every file should be a comment indicating the file’s name, author, date, and purpose.
- 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”.
- Before every class definition there must be comments indicating class invariants.
- 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.
- Only required headers should be included, and namespace pollution should be avoided.
- In particular, do not write “using namespace std;”.
- Also, where possible, avoid the “.h” system headers.
For example, prefer <cstdlib> to <stdlib.h>.
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.
- Requirements on template parameter types must be documented.
- Exceptions thrown by each function must be documented.
- Exception safety levels offered by each function must be documented.