diff --git a/_code_smells/bumpy_road.md b/_code_smells/bumpy_road.md index 437a751..3ba75ed 100644 --- a/_code_smells/bumpy_road.md +++ b/_code_smells/bumpy_road.md @@ -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). diff --git a/_code_smells/deep_nesting.md b/_code_smells/deep_nesting.md new file mode 100644 index 0000000..bf88af2 --- /dev/null +++ b/_code_smells/deep_nesting.md @@ -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).