Defect Indicators: Statements involving a condition have been nested to a depth of more than 4.
Risks: With more than 4 levels of nesting, programs become difficult to understand and therefore difficult to maintain. Programmers are more likely to introduce new errors when they make changes.
- Mark all the lines controlled by the 5th level of condition.
Remedy: Refactor the deeply nested code into its own routine, OR Redesign the tests in the condition, OR Write a comment justifying the level of nesting.
- Managing the Structured Techniques: Strategies for Software Development in the 1990's (Edward Yourdon, Noam Chomsky, and Gerald M. Weinberg), 1986,
- Professional Software, vol. 2, Programming Practice (Henry F. Ledgard, and John Tauer), 1987,
- Software Reliability (Glenford J. Myers), 1976,
- Some Pascal Style Guidelines (David Marca), 1981.
Few understand more than 3 levels of nesting:
Few people can understand more than 3 levels of nested "if" statements,
More than 4 levels of nesting too difficult:
Many researchers recommend avoiding going to more than four levels.