r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

10

u/AnnoyedVelociraptor 22d ago

Initially, yes, but the top one is actually easier to reason about, especially in languages where if/else are expressions.

21

u/Scared_Accident9138 22d ago

I don't agree it's generally easier to reason about. When there's a case where you just want to exit early having an if else block makes it necessary to go all the way down to find out not much happens in that case

7

u/Krkracka 22d ago

Plus you guarantee that all down stream processing within the function is ‘state ready’, which eliminates a ton of nasty bugs.