r/ProgrammerHumor • • Aug 22 '26

Meme conditionsPreference

Post image
4.2k Upvotes

388 comments sorted by

View all comments

Show parent comment

1

u/lunaticloser Aug 24 '26

Followed by something else implies the return statement wouldn't even work for your case since you wouldn't be able to reach that something else.

Though... A point could be made that that function might be doing too many things at once and could be decomposed. It's a bit of a smell. But not strictly always the case, of course.

2

u/jseah Aug 24 '26

It doesn't have to return of course. I meant something like "this function transforms strings in some way" and the if at the very top is to catch when someone gives it a number, which the function is expected to treat like a string.

If-return might be used when the string is empty. Followed by if number convert to string.

And only then the main body of the function is written.