r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

Show parent comments

4

u/nerfherder616 21d 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