Remove Nested Control Structures
Intent
Re-structure code so that deeply nested or complicated control structures are replaced by semantically identical versions. Special case of Refactoring, similar to Untangle Code. Often performed by reducing complexity and especially cyclomatic complexity. When reducing code complexity one needs to make sure we’re not exchanging inner/ method/ cyclomatic complexity by outer/ design or runtime complexity.
Related patterns
-
Refactoring stub
Source code transformation that does not change functionality of system. See [Fowler-Refactoring].
-
Untangle Code stub
Remove unnecessary complications in code, e.g. nested structures, dependencies, dead-code, duplicate-code etc. See Remove Nested Control Structures. Special case of Refactoring.
-
Handle If-Else Chains stub
Refactor nested if-then-else structures for improved understandability. Can be seen as a specialisation of Remove Nested Control Structures.
Found a mistake or want to add your experience? Edit this pattern on GitHub.