This metric measures the maximum nesting depth in a file. This includes nested branch and loop statements, but not blocks.

Deep nesting makes code very difficult to read and modify, and is also a sign that a function/class has lost cohesion (i.e. is doing too many unrelated things). Try to keep nesting depth below 7 levels.

Reduce the nesting in the file by putting the code in the inner loops/branches in separate functions.

  • M. Fowler. Refactoring. Addison-Wesley, 1999.
  • Wikipedia: Code refactoring
  • Refactoring as Meta Programming?