Goto Still Considered Harmful

Goto (still) ConsideredHarmful [1] is a BuzzGroup? and FishBowl session at ObjectTechnologyTwoThousand

MartineDevos, JimCoplien and AlanoCallaghan? would love your (advance) contribution.

Here is the idea:

During our (short) history as a software profession, we made some statements that last, that survive. "Goto considered harmful" is one of them. But do we always get the reactions, the results we expect? When an OO-guru says "ComponentsAreNotObjects?" these four words are used to communicate a lot of meaning. Academics (and gurus) are experts at communicating wisdom a few words, and often assume that a lot of foreknowledge among their audience. But that audience is not limited to computer scientists. Our managers don't always have that knowledge, neither do some (Java in 24 hours). They may go for easy money, follow the hype, or often just literally do "what we told them to do".

What do we create with our statements?

Can we avoid it? How do we avoid it?

Add to the list of MisUsedButWellMeant or start a discussion about one of them.

Thanks! MartineDevos


Goto Considered Harmful Considered Harmful: These compact statements are abstractions from lots of observations. Abstractions are powerful and this makes them attractive. The problem is that AllAbstractionsLie, and the discussion above could be considered a specialization of that pattern. There are cases where bad code can be improved by introducing gotos. Breaking out of nested loops in C or C++ would be one example. To avoid time-consuming religious wars on the harmfulness of goto, however, a more politically correct solution might be to rewrite the loops as a function and use a return statement to break out. Indeed, break, try-throw-catch, and return are special cases of goto, but avoid getting caught in GotoConsideredHarmful wars by using different names. --LarsAronsson

Break, exception, return statements, continuations and all the rest are not special cases of goto. On interpreted envirenments, there usually isn't even a goto involved. Maybe in your favorite language branches and function calls are compiled to jump statements, but that doesn't have to be. There is also a paradigm difference: when you program in a procedural or functional style, you don't care about the low level details of the machine, but on the high level properties of the computation. You don't think "i don't want to use a goto, so i'll create a function call". You abstract and refactor the code until it shows you that it wants a function, and if the problem were addressed in the right way, the function would have been there in the first place. -- AmirLivne

Actually, they are. If/else and for/while are also special cases of goto. At some point, either the processor or the VM gets the command "inc IP, 22" or something like it. Go ahead, code a VM without a jump command and see how many languages it can run efficiently. --ColinvonHeuring

Are you claiming that 'compiles in a manner that includes a goto' is equivalent to 'is a goto'? If so, how do you justify such a claim? (I mean, it sounds a lot like claiming that a house is a special case of a door.) If not, how is it that you assert that conditional and looping constructs are 'special cases of a goto'?


And when you are coding a large (approx. 100 states) finite state machine?

Similar pages: GoTo, ConsideredHarmful, GotoConsideredHarmful


CategoryBranchingAndFlow


EditText of this page (last edited January 10, 2014) or FindPage with title or text search