GOTO statements are not bad, they make your code run 10% faster while taking just 10 times as long to debug. So if your code gets executed millions of times per second, like in some OS kernel, it may be wise to use GOTOs. Otherwise, stay away.
If goto statements are bad why does linux src have more than 10k of them?
31–40 of 48 posts
Re: If goto statements are bad why does linux src have more than 10k of them?
#32Contrary to popular reputation, there are a handful of use cases where "goto" makes the code simpler, cleaner, more readable, and (in rarer cases) faster. In these cases, you should use goto statements. A good programmer can recognize these cases and use goto appropriately. Goto is never necessary in a strict sense but occasionally it can eliminate some pretty ugly spaghetti code. The use cases for goto I see are pri…
Re: If goto statements are bad why does linux src have more than 10k of them?
#33Re: If goto statements are bad why does linux src have more than 10k of them?
#34The original context of the "GOTO considered harmful" is lost on most of us, as at the time there were large swaths of developers that were trained before structured programming took off, so people were using global variables and GOTOs instead of procedures and functions. GOTO has its place, specially in C. It is sinful to jump into a different function and pass around information as global state. GOTO as functionali…
>It is sinful to jump into a different function So sinful you can't in C
Re: If goto statements are bad why does linux src have more than 10k of them?
#35Contrary to popular reputation, there are a handful of use cases where "goto" makes the code simpler, cleaner, more readable, and (in rarer cases) faster. In these cases, you should use goto statements. A good programmer can recognize these cases and use goto appropriately. Goto is never necessary in a strict sense but occasionally it can eliminate some pretty ugly spaghetti code. The use cases for goto I see are pri…
EDIT: Upon closer inspection it seems like even if 'gotos' make everything nastier the extra added performance is worth it.
Re: If goto statements are bad why does linux src have more than 10k of them?
#36The original context of the "GOTO considered harmful" is lost on most of us, as at the time there were large swaths of developers that were trained before structured programming took off, so people were using global variables and GOTOs instead of procedures and functions. GOTO has its place, specially in C. It is sinful to jump into a different function and pass around information as global state. GOTO as functionali…
I've heard of that. It's called "exceptions", right?
I find it kind of amusing when people are afraid of "goto" but not "throw", "break" or "return".
Re: If goto statements are bad why does linux src have more than 10k of them?
#37Contrary to popular reputation, there are a handful of use cases where "goto" makes the code simpler, cleaner, more readable, and (in rarer cases) faster. In these cases, you should use goto statements. A good programmer can recognize these cases and use goto appropriately. Goto is never necessary in a strict sense but occasionally it can eliminate some pretty ugly spaghetti code. The use cases for goto I see are pri…
Breaking from nested loops with goto is also cleaner and simpler. Which is actually one of the reasons some higher level languages even have a goto statement.
Re: If goto statements are bad why does linux src have more than 10k of them?
#38The original context of the "GOTO considered harmful" is lost on most of us, as at the time there were large swaths of developers that were trained before structured programming took off, so people were using global variables and GOTOs instead of procedures and functions. GOTO has its place, specially in C. It is sinful to jump into a different function and pass around information as global state. GOTO as functionali…
> It is sinful to jump into a different function I've heard of that. It's called "exceptions", right? I find it kind of amusing when people are afraid of "goto" but not "throw", "break" or "return".
Re: If goto statements are bad why does linux src have more than 10k of them?
#39Contrary to popular reputation, there are a handful of use cases where "goto" makes the code simpler, cleaner, more readable, and (in rarer cases) faster. In these cases, you should use goto statements. A good programmer can recognize these cases and use goto appropriately. Goto is never necessary in a strict sense but occasionally it can eliminate some pretty ugly spaghetti code. The use cases for goto I see are pri…
Re: If goto statements are bad why does linux src have more than 10k of them?
#40Because it is written in C. "Goto statements are bad" meant: lets start using languages that offer higher level constructs to replace the current usage of goto. Things like "loops" and "functions" and "exceptions". C did not get the memo.
Writing something in C does not automatically imply having to use goto.
> "Goto statements are bad"
Goto statements are not bad.
> Things like "loops" and "functions" and "exceptions". C did not get the memo.
C has loops and functions. Bro do you even K&R?
It might be a good idea to know what you're going to be talking about before opening your mouth.