Coding guidelines

This is a list of guidelines that you should check your code against before submitting each assignment.
  1. Use meaningful variable names, but try to keep them short. Use a comment to describe the purpose of the variable if there is any question.
  2. Never use a variable for two different purposes.
  3. Avoid duplicate code. Either condense it somehow or write a function.
  4. Keep variables in as local scope as possible. Avoid global variables. Declare variables at initialization.
  5. Make variables const when possible.
  6. Use comment blocks rather than commenting every line.
  7. Avoid comments that state the obvious.
  8. Make comments meaningful.
  9. Always enclose the body of control structures (e.g. if, for, etc) in braces even if there is only one line in the body.
  10. Prefer for loops over while loops. Always use a for loop when an iteration variable is used and it can be kept in local scope.
  11. Prefer passing non-primitive data types as const reference parameters.
  12. Prefer having only one return statement per function.
  13. Avoid using break in loops.
  14. Use val->a() rather than (*val).a() when using iterators and pointers.
  15. Use val[i] rather than *(val+i) when using arrays.
  16. Keep class data members private.
  17. Never return a non-const reference to a class data member.