Code Inspection: why, when and what
What should you look for?
We advise you to choose a level of inspection corresponding to your Software Quality requirements: Entry-Level, Professional or Best Practice:
Entry Level Compliance—Look for Defect Indicators which are easy to find but are correlated with instability, errors and unnecessary complexity. The IfSQ Level-1 Standard (An Entry-Level Standard for Computer Program Source Code) takes account of the following research findings:
- A study showed that when routines averaged 100 to 150 lines each, code was more stable and required less changes,
- Routines with 143 lines or less are 2.4 times less expensive to fix than larger routines,
- A study at IBM found that the most error-prone routines were those larger than 500 lines of code,
- Few people can understand more than 3 levels of nested "if" statements,
- Many researchers recommend avoiding going to more than four levels,
- The DRY principle: Don't Repeat Yourself.
Professional Software Development—Look for Defect Indicators which have been correlated with low reliability, design flaws and high maintenance costs. The IfSQ Level-2 Standard (A Foundation-Level Standard for Computer Program Source Code) also takes account of the following research findings:
- Control-flow complexity has been correlated with low reliability and frequent errors,
- The competent programmer is fully aware of the strictly limited size of his own skull,
- Copy and Paste is a design error,
- 39% of all errors are caused by internal interface errors / errors in communication between routines,
- 50% to 80% of plain "if" statements should have had an "else" clause.
Industry Best Practice—Perform code walkthroughs to ensure that inappropriate techniques have been avoided. The IfSQ Level-3 Standard (Industry Best Practice for Computer Program Source Code) also takes account of the following research findings:
- A study of 450 routines found that 50 percent of highly cohesive programs were fault free, compared to only 18 percent of routines with low cohesion,
- Given a sample of 450 routines, the routines with the highest coupling-to-cohesion ratios had 7 times more errors than those with the lowest ratios,
- Routines with low cohesion can cost 20 times more to fix than fixing highly cohesive routines,
- The effort required to debug a program is minimized when variables had names averaging 10 to 16 characters long,
- 46 percent of routines with no unused variables had no errors compared to only 17 to 29 percent for those with one or more unreferenced variables,
- Large programs that use information hiding are a factor 4 easier to modify than programs which don't.