Today's small list of horrors, item #1:
read online
"Most coding standards no matter language ban multiple return statements from a single function as bad practice. "

@Jenkar Wait, is that saying you shouldn't have if statements that return things in functions? Or that you shouldn't have 2 returns (which cancel out because the function exits after returning, right?)

@MxCraven @Jenkar It doesn't always cancel out, if the first one is inside an if or something!

Early returns are extremely useful.

@IceWolf @Jenkar Oh yeah, if the first one is in a conditional, I meant like, straight back to back 2 return lines. It's just messy.

Otherwise since the func exits on return it's just an if else, without the else

@MxCraven @Jenkar Yeah exactly! But people for some reason hate returns anywhere other than at the absolute end. >,,>

@MxCraven @Jenkar Like 2 return lines make so sense, but they're not talking about that, they're talking ALL early returns.

@IceWolf @Jenkar But what if I *need* multiple returns? What if the function is testing something and I need some if and some else... And some stuff in between to mutate the returned value...

Do I just have to do that outside of a function?

@MxCraven @Jenkar Okay I have no idea where 'mutate the returned value' comes in because you've already returned...? right?

@IceWolf @Jenkar

If A then do this to a value and return B

If C then do this to the value and return B

else return B

Something like that. I assume that a basic "if else" is fine to them, because otherwise true false returns wouldn't be allowed.

@MxCraven @Jenkar Ah yeah exactly. That's the useful stuff and the stuff they hate.

@IceWolf @Jenkar Do they hate that more than redundant code that could be made into a function, or less? :P

@MxCraven the second one (only a single return in functions)

Sign in to participate in the conversation

the mastodon instance at is retiring

see the end-of-life plan for details: