News for hackers. Stuff that matters.
Re:If goto statements are bad why does linux src have more t... by estebank on Tuesday December 16, 2014 @09:46PM (#8760828)
The 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 functionality is tangential in this matter.

Re:If goto statements are bad why does linux src have more t... by danellis on Tuesday December 16, 2014 @09:56PM (#8760856)
Growing up in the 80s, that's how a lot of books taught us BASIC, because they catered to a lowest-common-denominator implementation. Fortunately, I was using BBC BASIC, with functions, procedures and REPEAT-UNTIL (and later WHILE and CASE), and the BBC-specific books taught structured programming.
Re:If goto statements are bad why does linux src have more t... by Immortalin on Tuesday December 16, 2014 @10:10PM (#8760890)
On error GOTO next
Re:If goto statements are bad why does linux src have more t... by danellis on Tuesday December 16, 2014 @11:22PM (#8761062)
The empty catch block of BASIC.
Re:If goto statements are bad why does linux src have more t... by teh_klev on Wednesday December 17, 2014 @05:43AM (#8761833)
For every line of code (just to be pedantic).

I have customers still churning out wads Classic ASP who think On Error Resume Next magically fixes their shabby code. Makes me weep.

Re:If goto statements are bad why does linux src have more t... by asveikau on Tuesday December 16, 2014 @10:48PM (#8760987)
> 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 t... by lukeschlather on Tuesday December 16, 2014 @11:00PM (#8761012)
You skipped the "and pass information around as global state" part. It obviously depends on your language, but ideally an Exception object should be a specific class you can choose to catch or re-raise, and it should include a message. None of the calling state should be visible to you.
Re:If goto statements are bad why does linux src have more t... by asveikau on Tuesday December 16, 2014 @11:14PM (#8761051)
I give you that I skipped it. I skipped it intentionally to make a bit of hyperbole.

An exception is still essentially a goto that crosses stack frames. There is a whole class of common bugs, you will see a lot of talk of them in the C and C++ communities, where an early return or a throw at an unexpected time leads to resources not being cleaned up. A lot of good coding styles say avoid this stuff, it's dangerous, and they are not without cause. Whereas a goto cleanup block is often a lot more explicit and therefore can lead to more reliable code than a scheme that encourages not sweating details and not expecting failure at every step.

Re:If goto statements are bad why does linux src have more t... by wcummings on Tuesday December 16, 2014 @09:58PM (#8760862)
>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 t... by astrange on Tuesday December 16, 2014 @10:23PM (#8760917)
You can do it in GNU C! It's used to write direct-threading interpreters.

https://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Labels-as-Values....

Re:If goto statements are bad why does linux src have more t... by knome on Tuesday December 16, 2014 @11:18PM (#8761057)
They don't intend for label addresses to be gone to outside of the function they are located in. The stack wouldn't be setup to handle them at all.

Sure, you can store them wherever, and do something like " goto *g_greenthreads[ threadno ].lastpos ", but you would call that within the function defining the label, not outside it.

From your own link: > You may not use this mechanism to jump to code in a different function. If you do that, totally unpredictable things will happen. The best way to avoid this is to store the label address only in automatic variables and never pass it as an argument.

Re:If goto statements are bad why does linux src have more t... by danudey on Tuesday December 16, 2014 @10:22PM (#8760916)
I assumed the parent poster meant back before functionality was expressed as functions; i.e. it's sinful to jump from functionality A to functionality B if it's not expressed in terms of packaged functions, and impossible to do so if it is.
Re:If goto statements are bad why does linux src have more t... by tormeh on Tuesday December 16, 2014 @10:37PM (#8760958)
With longjmp you can. Your stack will be trashed, though, so any state better be global!