Skip to content

Commit

Permalink
bumpy road and deep nesting are actually different but related smells
Browse files Browse the repository at this point in the history
  • Loading branch information
emilybache committed Jan 17, 2024
1 parent 67b8a23 commit d92a64a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 3 additions & 7 deletions _code_smells/bumpy_road.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ source: Adam Tornhill
---

# Bumpy Road
Code is easier to read if all the code in the same block has the same level of indentation. Most editors will automatically format code with indentation if you ask them to. You notice a bumpy road smell when the code has so many nested conditionals and loops that the indentation gets very deep, and/or varies a lot.
If a method or function has several sections each with a [Deep nesting]({% link _code_smells/deep_nesting.md %}) smell, then the indentation will form a lumpy pattern with several 'bumps'. Each section with deep nesting probably represents a different responsibility or action that could usefully be separated out into its own function.

Bumpy road 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 heavily indented code is very likely to be beyond human capabilities of comprehension just because there are so many things to keep in mind at once.
## More information

## Other names for this smell

This smell has many other names, for example **Heavy Indentation** or **Deep Nesting**. The name "Bumpy Road" comes from an article by Adam Tornhill [The Bumpy Road Code Smell: Measuring Code Complexity by its Shape and Distribution](https://codescene.com/blog/bumpy-road-code-complexity-in-context).

In Michael Feathers book "Working Effectively with Legacy Code" he describes a similar smell: a **Snarled method** is one "dominated by a single large, indented section". It's a Bumpy Road with only one bump. Similarly the C2 wiki describes the [ArrowAntiPattern](http://wiki.c2.com/?ArrowAntiPattern).
The name "Bumpy Road" comes from an article by Adam Tornhill [The Bumpy Road Code Smell: Measuring Code Complexity by its Shape and Distribution](https://codescene.com/blog/bumpy-road-code-complexity-in-context).
16 changes: 16 additions & 0 deletions _code_smells/deep_nesting.md
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).

0 comments on commit d92a64a

Please sign in to comment.