C Programming Language Style and Conventions
This page last updated: Sunday September 27, 1998 01:07
- write it once, and only once
- so that modifications require one change, in one place
- because less code is better code
- use only -1, 0, and 1 as constants
- #define everything else to be meaningful
- even better - use enum for constants
- boolean != NULL != 0 != \0
- keep your data types separate
- check and validate input (including excess)
- don't ignore any user input
- dont modify function arguments
- copy the arguments to temporaries if needed
- fopen/fclose malloc/free at same level
- don't hide file open/close in functions
- don't hide malloc and free in functions
- check function return codes
- if it can fail, test it
- write cover functions to avoid duplicating the testing code
- read input in only one place
- avoid global variables
- because you never know who changes them
- use the static keyword wherever possible
- print really good error messages
- not "too big"; instead: "bigger than %d bytes"
- get the code right first, then optimize
- put short, explanatory comments at the start of blocks of C code
Ian D. Allen CST8152 Home Page
This page last updated: Sunday September 27, 1998 01:07