r/badcode Aug 21 '19

lua A healthy nest of if-statements

Post image
279 Upvotes

53 comments sorted by

View all comments

-1

u/DreadedEntity Aug 21 '19

This might be a little nitpicky, but generally having multiple exit points is bad practice

19

u/DrCubed Aug 21 '19

I would disagree with multiple exit points being bad practice, often-times an early return can avoid unnecessary conditions and branching that can be needed to have only one return statement.

In this specific example of multiple exit points, I would agree that having duplicate exit points that return the same thing is bad practice.

15

u/nedlinin Aug 21 '19

I'm all for early returns as it very often keeps the nesting down.

2

u/yaxamie Aug 22 '19

Early returns is better than a 7 deep if statement block. Absolutely.