Skip to main content
added 178 characters in body
Source Link
sea-rob
  • 6.9k
  • 1
  • 25
  • 47

The more general advice is: watch out for deep levels of nesting. I've heard it called the "arrowhead" or "mountain range" anti-pattern, because that's what the code starts to look like. If you're nesting 2 levels for loops, then another level for if...then, and then if..thens inside the if...thens, the level of nesting can make the code really hard to follow.

  • I read an article where a team had huge maintenance problems with their code, so they implemented a policy of a maximum depth of nesting. Their bug rate dropped to almost nothing.

  • Someone famous once said, any code nested more than 3 layers deep is incomprehensible.

Hm. I can't find that quote now, but I did find a related article about nesting if...thens:

http://www.drdobbs.com/architecture-and-design/refactoring-deeply-nested-code/231500074

EDIT: here it is: "if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program."

https://www.kernel.org/doc/Documentation/CodingStyle

The more general advice is: watch out for deep levels of nesting. I've heard it called the "arrowhead" or "mountain range" anti-pattern, because that's what the code starts to look like. If you're nesting 2 levels for loops, then another level for if...then, and then if..thens inside the if...thens, the level of nesting can make the code really hard to follow.

  • I read an article where a team had huge maintenance problems with their code, so they implemented a policy of a maximum depth of nesting. Their bug rate dropped to almost nothing.

  • Someone famous once said, any code nested more than 3 layers deep is incomprehensible.

Hm. I can't find that quote now, but I did find a related article about nesting if...thens:

http://www.drdobbs.com/architecture-and-design/refactoring-deeply-nested-code/231500074

The more general advice is: watch out for deep levels of nesting. I've heard it called the "arrowhead" or "mountain range" anti-pattern, because that's what the code starts to look like. If you're nesting 2 levels for loops, then another level for if...then, and then if..thens inside the if...thens, the level of nesting can make the code really hard to follow.

  • I read an article where a team had huge maintenance problems with their code, so they implemented a policy of a maximum depth of nesting. Their bug rate dropped to almost nothing.

  • Someone famous once said, any code nested more than 3 layers deep is incomprehensible.

Hm. I can't find that quote now, but I did find a related article about nesting if...thens:

http://www.drdobbs.com/architecture-and-design/refactoring-deeply-nested-code/231500074

EDIT: here it is: "if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program."

https://www.kernel.org/doc/Documentation/CodingStyle

Source Link
sea-rob
  • 6.9k
  • 1
  • 25
  • 47

The more general advice is: watch out for deep levels of nesting. I've heard it called the "arrowhead" or "mountain range" anti-pattern, because that's what the code starts to look like. If you're nesting 2 levels for loops, then another level for if...then, and then if..thens inside the if...thens, the level of nesting can make the code really hard to follow.

  • I read an article where a team had huge maintenance problems with their code, so they implemented a policy of a maximum depth of nesting. Their bug rate dropped to almost nothing.

  • Someone famous once said, any code nested more than 3 layers deep is incomprehensible.

Hm. I can't find that quote now, but I did find a related article about nesting if...thens:

http://www.drdobbs.com/architecture-and-design/refactoring-deeply-nested-code/231500074