If Go To statements are bad then why ...
... are there countless abstractions and programming language mechanisms that bounce you around the text in ways that Go TO could have never dreamed of. I rarely spend time thinking about stuff like this but sometimes, just sometimes, the question just begs to be asked (again).
4 comments
[ 3.5 ms ] story [ 16.8 ms ] threadLike? What are those abstractions and mechanisms?
Well written programs can (and do) make use of no such mechanisms, in any case. Where have you seen those? Any particular example that moves the flow the way Goto does?
Exceptions come to mind, and people always point out that its bad to abuse exceptions for control flow (e.g. using them like a kind of goto).
The problem with goto (which is not considered a problem when used in local scope, e.g. for cleanup code within a function) is that it moves the flow of execution away and makes it difficult to track.
A function (or e.g. a continuation in Node) doesn't have that problem: you return back to where you started.
Usually what I found is people feeling the need to use goto often just didn't understand how to design or layout the system they were working on, or try to put to many unrelated code segments into a function. As other comments mention, the flow of control changing scope etc cause lead to all kinds of difficult debugging, memory leaks, crashes etc. So not generally a good idea. Smarter to use proper function scoping, return behavior and error codes.
One of my early tasks as a C programmer, back in the early 90's, was taking a C program that had like only 4-5 functions (with thousands of lines of code) in it, and tons of goto's and cleaning it up to be a maintainable system. Engineers all hated that system because it ran fairly stable (somehow), but touching a single line of code could mean days of debugging. Starting over was easiest but took forever to get the functionality correct because of all the jumps to weird places that were not obvious behaviors. That was an unforgettable lesson for me.