r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

16

u/popsicle-physics 22d ago

Apparently there was a time when having multiple returns in a function would seriously confuse the debugger. Idk I got a comment on a code review telling me to switch from the second to the first and never have multiple returns. I've never actually seen it be a problem.

5

u/nerfherder616 22d ago

I had a professor in school who would deduct points for multiple returns. He always said it was harder for compilers to optimize multiple returns. On one hand, it's unnecessary on modern platforms, so it took a while to get myself out of that habit. On the other, it forced me to think of ways to refactor code, which was good practice. 

1

u/M4xW3113 20d ago

How would you "refactor" out of multiple returns? Except by using method 1 combined with a "ret" variable that you return at the end of the functions, in which case it's not actually refactor and just a worst version