DEV Community

Discussion on: When is nesting good or neutral?

Collapse
 
jacoby profile image
Dave Jacoby

I recently took a function with many nested ifs to modify two variables and rewrote it to return immediately instead. It was much more readable but didn't work when put into testing, but the point is that nesting makes things more complicated and harder to read.

That can be necessary; required behaviors can be complex. But it's kinder to your brain and those of the next dev to flatten.