Code - TheRedLady/nemetschek_internship GitHub Wiki
Organizing Straight-Line Code
- Does the code make dependencies among statements obvious?
- Do the names of routines make dependencies obvious?
- Do parameters to routines make dependencies obvious?
- Do comments describe any dependencies that would otherwise be unclear?
- Have housekeeping variables been used to check for sequential dependencies in critical sections of code?
- Does the code read from top to bottom?
- Are related statements grouped together?
- Have relatively independent groups of statements been moved into their own routines?
Using Conditionals
if-then Statements
- Is the nominal path through the code clear?
- Do if-then tests branch correctly on equality?
- Is the else clause present and documented?
- Is the else clause correct?
- Are the if and else clauses used correctly—not reversed?
- Does the normal case follow the if rather than the else? if-then-else-if Chains
- Are complicated tests encapsulated in boolean function calls?
- Are the most common cases tested first?
- Are all cases covered?
- Is the if-then-else-if chain the best implementation—better than a case statement?
Loops
Entering the Loop
- Is the loop entered from the top?
- Is initialization code directly before the loop?
- If the loop is an infinite loop or an event loop, is it constructed cleanly rather than using a kludge such as for i = 1 to 9999?
Inside the Loop
- Does the loop body have something in it? Is it nonempty?
- Are housekeeping chores grouped, at either the beginning or the end of the loop?
- Does the loop perform one and only one function, as a well-defined routine does?
- Is the loop short enough to view all at once?
- Is the loop nested to three levels or less?
- Have long loop contents been moved into their own routine?
- If the loop is long, is it especially clear?
Loop Indexes
- If the loop is a for loop, does the code inside it avoid monkeying with the loop index?
- Is a variable used to save important loop-index values rather than using the loop index outside the loop?
- Is the loop index an ordinal type or an enumerated type—not floating-point?
- Does the loop index have a meaningful name?
- Does the loop avoid index cross-talk?
Exiting the Loop
- Does the loop end under all possible conditions?
- Does the loop use safety counters—if you've instituted a safety-counter standard?
- Is the loop's termination condition obvious?
- If break or continue are used, are they correct?