The overriding principles are:
- The code must be properly credited,
- The code must be elegant,
- The code must be readable.
Further specifications are given here for those who are uncertain
as to the meaning of the above overriding principles.
The code must be properly credited
- The header of each file includes name, course number, semester, project number, a title or brief description.
- Any code that has been cannabilized must be credited to its originator, unless that code appears in the
currently used textbook, was supplied by the instructor, or the instructor explicitly said you didn't have
to credit the source.
The code must be elegant
- There are no unnecessary variables nor unnecessary executable statements.
- Unless there are performance issues, code should be organized into functions that are reasonable and logical.
- Each function should fit on at most one page (approximately 30 lines of code).
- Unless there are performance issues, use global variables only to minimize parameter passing and to make clean functions.
- Always use standard algorithms when possible.
- Don't put code inside loops or inside recursive functions unless absolutely necessary.
The code must be readable
- Unless there are other factors (such as performance or specification requirements), use the most readable algorithm.
- Be consistent in all your style.
- Use good naming practice
- Variables with small scope should have short names, those with larger scope have longer names.
- Names are descriptive (except for loop control).
- Use case properly: variables start with lower case, constants are all upper case.
- Variables (except loop control) are declared in a function before any executable statements.
- Keep your exit points few and logical. Avoid break and continue unless the code is improved by using them.
- Use comments to help the reader
- Whitespace -- above all, be consistent.