Pyramid of doom
and how to avoid it.
So nested that no ray of light can penetrate trough. Endless maze of nested statements that leads to nowhere — a point of no readability and no manageability.
A pyramid of doom is a block of code that is so nested, that you give up trying to understand what it does. It’s programming suicide.
Avoid is the right answer to this problem. How? Check bellow!
function doSomething():
if (condition):
if (condition):
if (condition):
if (condition):
if (condition):
if (condition):
....
end;
end;
end;
end;
end;
end;
end;
#1 Plan ahead
#2 Confirm what your function needs to achieve
#3 Try to follow SOLID principles
#4 Simplify
#5 Refactor
#6 Use early return
#7 Use polymorphism
#8 Make your function pure
#9 One level of abstraction per function
#10 Always aim for smaller functions even if they look too small
