Good coding practices are a major part of your final grade. Your future boss might not care what your code looks like, but I do. I will be looking at your svn code. The grade for coding practices will be assigned mostly at the midterm demo and on the final project.

Always remember to write code for someone else to read, someone who knows nothing about the details of your program, because that someone else is you, six months from now.

Refer to Chapters 10–19 of the textbook for details on effective coding practices.


  1. Do you always ensure that argument values are valid?
  2. Declare variables close to where they are used.
  3. Initialize variables as they are declared.
  4. Do all variables have the smallest scope possible?
  5. Are references to variables as close as possible?
  6. Do control structures correspond to data types?
  7. Are all declared variables used?
  8. Does each variable have one and only one purpose?
  9. Is each variables meaning, and name, explicit? with no hidden meanings?
  10. Do your variable names follow your coding practice?
  11. Does the name refer to the real-world problem rather than the programming-language solution?
  12. Is the name long enough that you don't have to guess?
  13. Are computed-value qualifiers at the end of the name?
  14. Are loop index variable names meaningfull? i and j should only be used for loops of only a couple of lines.
  15. Have you re-named all "temporary" variables?

Data Types

  1. Do you have any magic numbers?
  2. Does the code anticipate divide by zero errors?
  3. Are type conversion obvious?
  4. Do you avoid mixed-type comparisons?
  5. Are you doing integer division?
  6. Are you checking for integer overflow?
  7. Do you avoid adding or subtracting floating point numbers of very different magnituded?
  8. Do you avoid comparing floating point numbers for equality?
  9. Does the program use additional boolean variables to document conditional tests? to simplify tests?
  10. Do you use enumerated types instead of named constants when appropriate?
  11. Are all array indexes withing the bounds of the array?
  12. Are array references free of off-by-one errors?
  13. Are type names oriented towards the real-world entitites the types represent rather than toward programming-language types?
  14. Have you avoided re-defining predefined types?


  1. Does the code make dependencies among statements obvious?
  2. Do the names of routines make dependencies obvious?
  3. Do parameters to routines make dependencies obvious?
  4. Do comments describe any dependencies that would otherwise be unclear?
  5. Does the code read from top to bottom?
  6. Are related statements grouped together?
  7. Have relatively independent groups of statement been moved into their own routines?


  1. Is the nominal path through the code clear?
  2. Is the else clause present and documented?
  3. Are the if and else clauses used correctly—not reversed?
  4. Does the normal case follow the if rather than the else?
  5. Are complicated tests encapsulated in boolean function calls?
  6. Are the most common cases tested first?
  7. Are all cases covered?


  1. Is a while loop used instead of a for when appropiate?
  2. Is the initialization code directly before the loop?
  3. If it is an infinite loop, is it clear that it is? Is any exit clear?
  4. Is the loop body nonempty?
  5. Does the loop perform one and only one function, as a well-defined routine does?
  6. Is the loop short enough to view all at once?
  7. Is the loop nested to three levels or less?
  8. In a for loop, do you avoid changing the index variable?
  9. Do you avoid using the index variable outside the loop?
  10. Does the index variable have a meaningful name?
  11. Does the loop avoid crosstalk?
  12. Does the loop end under all possible conditions?
  13. Does the loop use safety counters?
  14. Is the loop's termination condition obvious?

Jose M Vidal
Last modified: Mon Jul 28 15:11:24 EDT 2008