Coding guidelines
This is a list of guidelines that you should check your code
against before submitting each assignment.
- Use meaningful variable names, but try to keep them short.
- Never use a variable for two difference purposes.
- Avoid duplicate code. Either condense it somehow or
write a function.
- Keep variables in as local scope as possible.
- Make variables const when possible.
- Use comment blocks rather than commenting every line.
- Avoid comments that state the obvious.
- Make comments meaningful.
- Always enclose the body of control structures (e.g. if, for, etc) in
braces even if there is only one line in the body.
- Prefer for loops to while loops. Always use a for loop when
the iteration variable will be incremented the same each iteration.
- Prefer passing non-primitive data types as const reference
parameters.
- Keep class data members private.
- Never return a non-const reference to a class data member.
- Use val[i] rather than *(val+i) when using arrays.
- Use val->a() rather than (*val).a() when using pointers.