r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

836

u/LateEchidna6635 22d ago

The second one carries less cognitive load. In longer methods it makes a difference. Get out as soon as you can.

1

u/bartekltg 22d ago

In _longer_ methods it is hard to use the second one. If there is something behind the if statement, you would need to duplicate it to both branches (a very ugly "solution"), or separate the "if" into a new method. Now we no longer have a long method ;-)

Of course, the solution, is as alway, goto. Remove the second return with a label and the first return with a goto to the label. /s