-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bumpy road and deep nesting are actually different but related smells
- Loading branch information
1 parent
67b8a23
commit d92a64a
Showing
2 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
layout: code_smell | ||
title: Deep Nesting | ||
source: Emily Bache | ||
--- | ||
|
||
# Deep Nesting | ||
If code has many conditionals and loops nested inside one another, perhaps more than about 3 levels, then you'd say it has "deep nesting". It is a sign that the [cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) of the code is high, and the code is difficult to read and comprehend. The human brain has a limit of how much complexity it can hold at once, and deeply nested code is very likely to be beyond human capabilities of comprehension just because there are so many things to keep in mind at once. | ||
|
||
If a method or function has several sections each with deep nesting then you would call it a [Bumpy Road]({% link _code_smells/bumpy_road.md %}) smell. | ||
|
||
Most editors will automatically format code with indentation if you ask them to. You easily notice a deep nesting smell when the code has so many nested conditionals and loops that the indentation gets very deep. | ||
|
||
## Other names for this smell | ||
|
||
This smell is also known as **Heavy Indentation** because of the shape it makes on the page. In Michael Feathers book "Working Effectively with Legacy Code" he describes a **Snarled method** is one "dominated by a single large, indented section". The C2 wiki describes the [ArrowAntiPattern](http://wiki.c2.com/?ArrowAntiPattern). |