CS712/CS812
Coding Conventions
Spring 2003
The code you write should conform to the following conventions:
- No tabs. They are evil!
- Use consistent indentation. (Preferably two-space indentation.)
- Lines should be no longer than 80 characters.
- Declare only one identifier (e.g. variable) per line.
- Use Java-style names. charsPerLine rather than chars_per_line.
- Use meaningful names (in English).
- Always use function prototypes.
- Avoid long functions.
- Function bodies should be well-commented. Something that is
obvious to you in February may not be obvious to either you or me
in April.
- Use symbolic constants when appropriate.
- Place { and } in a consistent manner.
- Use blank lines liberally to improve readability.
- Each function should have a header comment describing its purpose.
- Avoid global variables. I need to approve each global variable that is
visible across multiple files.
- Use "static" to hide functions and global variables that do not need
to be visible across multiple files.
- All code should compile cleanly, with no warnings (unless I explicitly
approve them).
- Test all library calls (e.g. malloc) for failure.
- Use the "message" module to report errors (both internal and user).
Also, you need to avoid C constructs that our compiler does not implement:
- No initializers.
- No bitfields.
- No old-style functions.
- No // comments.
- No other ANSI 1999 features.
Last modified on February 13, 2003.
Comments and questions should be directed to
hatcher@unh.edu