Simplify Nested Code
February 17, 2025
One of the most common pieces of feedback I leave in code reviews, at least in the realm of code readability, is to reduce nesting. In general, the more deeply-nested code is, the more complex it is to track mentally. This is especially the case with if statements.
Source: Simplify Nested Code
I have a strong aversion to nesting of if statements at all–though will do one level if I have to–beyond that it’s almost physically impossible for me to do so. Even thinking about it raises my blood pressure.
So, here are some strategies and patterns for managing nested code.