oh wait, so you meant the font thats actually used in the comics, I thought you meant that there was some sort of an xkcd comic which talked about a weird font. Sorry lol
Huh I'm on mobile web right now and your link doesn't work (the ending parentheses visible instead of being part of the link), maybe it's not rendered in a consistent way between desktop and mobile web?
wow yea you're right. i'm on desktop now and now your link is fine and mine's the one that's basically broken even though it works as intended on chrome android. i guess the only way to get a link working everywhere is to paste the url itself and not try to use a markdown style link
I hate nested ifs but every PR I put up people tell me it's confusing that there are multiple return statements in the function. They also say the implicit state is confusing as well. SMDH.
One of the things I was taught in college that seems to be ignored by just about everyone:
Every Procedure or Function should have exactly One Entry Point and One Exit Point. Any more and you are writing spagetti and need to rethink your code.
I will admit to violating this rule on a number of occasions but still do what I can to follow it.
In most programming languages one entry point per function is a given, but explain to me exactly how multiple exit points leads to spaghetti because my experience has been the opposite. Forcing yourself to only return once is how you end up with giant if chains like in the OP.
I also rember learning that in college and immediately thinking "that's bs" because of the experience described above.
For C/C++ it totally makes sense because memory management and scope is really important in that language and early returns can cause you to not "clean things up" properly but for most other languages this isn't an issue whatsoever.
And to give you a bit more of my perspective: multiple returns are about focusing on the happy path. It makes much more sense to me to read a program where the "happy path" is at the base level indentation and the error-checking happens inside if statements.
The second one, like the OP, I look at any say "Oh, if these 3 or 7 things all happen to be true, then whatever, that's unlikely." So the whole function looks like it's just some stupid bug fix for some edge case someone didn't know how to handle correctly.
I look at the first function and think "Oh, that does something important but it might fail for some reasons."
And whoever learned one return statement per function needs to get off the C77 standard. That's been outdated for at least 40 years. If you have an instructor telling you that, let the chair of the department know you're unable to take classes from someone who is so out of date.
In my experience, this is one rule that should be avoided today.
Obviously, randomly placed returns in a gigantic function make readability worse. The problem here is primarily the gigantic function. Having guard statements with early returns is one simple strategy to reduce nesting and complexity of a function.
156
u/TheJP_ Dec 10 '21
Vb is basically cheating for this subreddit
59
u/SystemIntegrat0r Dec 10 '21
I really like how the beginning of end aligns perfectly with the beginning of if in the next line
56
u/noreal Dec 10 '21
Nothing’s wrong this is just low-params neural network
15
u/stahkh Dec 10 '21
In case somebody wonders what is a quick fix for nested conditionals: guard statements.
You might also want to factor out some methods.
9
u/moopet Dec 10 '21
If Matthew Mcconaughey was a programmer.
5
u/CaitaXD Dec 10 '21
Use logical and ffs
1
u/RadioMelon Dec 27 '21
The first step is recognizing there's a problem.
The second step is screaming and trying to fix it. The screaming part is important.
1
u/georgi544 Dec 10 '21
End if