SP-3—Routine Too Complex
Defect Indicators: A program (method, module, routine, subroutine, procedure, or any named block of code) contains more than 10 binary terms in conditional statements.
Risks: Programs containing more than 10 comparisons are more difficult to understand and therefore more difficult to maintain. Programmers are more likely to introduce new errors when they make changes.
A simple way to count the comparisons in a program is to locate the comparison expressions by looking for the keywords that introduce them. This method is based on McCabe's Complexity Metric.
Assessment: Locate and count all binary terms in the program. An easy way to do this is by looking for the keywords and symbols that can precede them in the language you are using. For example:
- If, While, Until, etc.
- And, Or, &&, ||, etc.
Mark all the binary terms after the 10th occurrence.
- Simplify complicated tests with Boolean function calls, OR
- Refactor the complex code into separate routines, OR
- Restructure the program to remove any unnecessary repetition.
- A Complexity Measure (Tom McCabe), 1976,
- Identifying Error-Prone Software - An Empirical Study (Vincent Y. Shen, Tze-jie Yu, S.M. Thebaut, and L.R. Paulsen), 1985,
- Software Defect Prevention Using McCabe's Complexity Metric (William T. Ward), 1989,
- The Humble Programmer (Edsger Dijkstra), 1972.