Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I am supposed to "bring the code up to corrent standards".
RN I'm staring at this instrument of torture with 3 different return statements (but 4 branches, so one branch DOESN'T RETURN ANYTHING AT ALL) and at the bottom of the function there's a logger which of course is almost never called since for 3 branches out of 4 it returns before even reaching it.
The return themselves are sometimes a promise, sometimes a raw value, sometimes undefined.
I'll start linking this shit everywhere from now on, this is getting unnerving
https://en.wikipedia.org/wiki/... -
@miladiashe It's not, but it's still better than having just one return inside an if-else statement
-
@miladiashe your Git says your code is already good. Wanna switch places with whoever-is-responsible-for-this-mess-I'm-fixing?
-
@miladiashe What's pretty common is the idiom of doing any sort of input or condition checking at the beginning of a function and return an error code if something isn't right. No big if-else branch, just early return.
The rest of the function can then be written under the assumption that all that stuff has already been ruled out. So that would be two returns for that idiom. -
-
@miladiashe Btw., if you start introducing artificial flag variables in loops so that you can prematurely exit the loop without using a break, your code will be so clean that you'll see why people hated Pascal. ^^
-
@miladiashe The difference is that you don't have a break. It's like putting so much lipstick on a pig that you can't see the pig anymore.
-
The first comment smells untyped..
I don't see an issue with sensibly used multiple returns in statically typed languages. And even abused they are better than »goto exit; //but not really as there's stuff happening after the jumpmark«. -
@saucyatom
Yes, that is the real issue: Not using static analysis at all.
Doesn't have to be a compiler. Even static analyzers for PHP find a lot of the common bugs.
Related Rants
The masculine urge to skew a scredriver in the lungs of the very funny colleague who place several random return statements inside their function
rant
return