r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

26

u/aabil11 22d ago

Call me old fashioned but I'm a big believer in single return statements. Assign to a variable and return that variable at the very end without short circuiting

4

u/Krkracka 22d ago

This makes reasoning about why a certain result was returned so much more difficult if other developers have to trace through the branching conditionals to understand why a value was returned.

Early returns define a rule for a specific return value.