Products > Programming
Goto bad Spooktober tale: Counting goto in the Linux kernel
thm_w:
--- Quote from: Siwastaja on October 29, 2023, 11:02:22 am ---
--- Code: ---int do_thing()
{
turn_relay_on();
if(!good_to_go)
{
turn_relay_off();
return FAILURE_1;
}
if(asdf != 123)
{
turn_relay_off();
return FAILURE_2;
}
do_rest_of_stuff();
turn_relay_off();
return SUCCESS;
}
--- End code ---
--- End quote ---
You can write it this way instead:
--- Code: ---int do_thing()
{
turn_relay_on();
if(!good_to_go)
result = FAILURE_1;
else if(asdf != 123)
result = FAILURE_2;
else
{
do_rest_of_stuff();
result = SUCCESS;
}
turn_relay_off();
return result;
--- End code ---
Anything that relies on copy pasting required steps in multiple locations is generally bad code. Regardless of having goto's or not.
cfbsoftware:
--- Quote from: DiTBho on November 01, 2023, 07:31:33 pm ---Damn, this is the common pattern here in this forum(2), and it's really frustrating!
--- End quote ---
I believe it would help let off steam in this forum if we could just mark a message as "Say No Thanks" instead of "Say Thanks" and then move on.
SiliconWizard:
--- Quote from: cfbsoftware on November 01, 2023, 11:39:05 pm ---
--- Quote from: DiTBho on November 01, 2023, 07:31:33 pm ---Damn, this is the common pattern here in this forum(2), and it's really frustrating!
--- End quote ---
I believe it would help let off steam in this forum if we could just mark a message as "Say No Thanks" instead of "Say Thanks" and then move on.
--- End quote ---
That's not a bad idea indeed.
Siwastaja:
That idea has been discussed before and while on surface it looks like a good idea, it quickly becomes stack overflow / reddit type "downvote into oblivion" system. "Thank you" thing might be unnecessary, but at least it's mostly positive (even that is used in a nasty way, "thanking" some users from very low-quality contributions just because they disagreed with someone with "wrong" opinion, but that use pattern is at least complex and thus not too common, compared to direct downvoting).
Users already have a way "to move on". Everyone posts here at their free will. Being able to be negative against people in a yet another (and easier!) way only results in more negativity, not "moving on".
metertech58761:
When I started learning C++, I too was told "GOTO bad. VERY BAD. Here your dunce cap. Stand in corner!"
After stewing on that a while, I came up with a different take; I write the code as I please, then go back and say "How many GOTO can I take out and still understand what's going on?"
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version