# GOTO lazy programming?

**URL:** <https://boards.straightdope.com/t/goto-lazy-programming/556186>\
**Category:** In My Humble Opinion\
**Created:** [October 5, 2010, 11:00pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186 "2010-10-05T23:00:31Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Superfluous\_Parentheses](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Superfluous\_Parentheses](https://boards.straightdope.com/u/Superfluous_Parentheses)\
**Post date:** [October 6, 2010, 3:59pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/21 "2010-10-06T15:59:56Z")

</div>

Gotos are too low level to use directly. Using them means you’re either lazy, or your language is too primitive (and probably both).

---

<div class="post-metadata">

**Author:** ![Lanzy](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@Lanzy](https://boards.straightdope.com/u/Lanzy)\
**Post date:** [October 6, 2010, 5:16pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/22 "2010-10-06T17:16:07Z")

</div>

I took some programming in 1976 at Univ of TN and anyone using GOTO would be dropped a letter grade for each instance.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [October 6, 2010, 5:57pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/23 "2010-10-06T17:57:36Z")

</div>

> [@Balthisar](#):
>
> Even most modern programming languages have disguised versions of GOTO that are in common use. Typically used for error/exception tracking, you might see a construct (meta language here) like ON ERROR MY\_LABEL;, and then at the end of the function, MY\_LABEL: handle\_exception();

Those are nothing like GOTOs, but model interrupts which are important parts of real machines. I suspect people today don’t learn about them, since for the most part the OS handles them.

Any construct which interrupts flow of control, goes somewhere and does something and then returns, is not a problem for structured code (and in fact often improves it) and has nothing to do with gotos except the letters G and O.

---

<div class="post-metadata">

**Author:** ![BobArrgh](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bobarrgh/32/2881_2.png) [@BobArrgh](https://boards.straightdope.com/u/BobArrgh)\
**Post date:** [October 6, 2010, 6:09pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/24 "2010-10-06T18:09:22Z")

</div>

I think it can be argued that some modern programming constructs are actually disguised GOTOs. For example, the “continue” statement placed near the top of a loop indicates that the rest of the loop is to be skipped for that iteration. The code goes back to the the beginning of the loop.

So, while the GOTO has been denigrated and vilified, its effects are still maintained, albeit in a more-supported fashion.

---

<div class="post-metadata">

**Author:** ![Nobody](https://avatars.discourse-cdn.com/v4/letter/n/94ad74/32.png) [@Nobody](https://boards.straightdope.com/u/Nobody)\
**Post date:** [October 6, 2010, 6:35pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/25 "2010-10-06T18:35:57Z")

</div>

> [@Balthisar](#):
>
> There was always the old DEF FNxx(y), but as a young kid I didn’t really get the grasp for that at the time, and used GOSUB’s as quasi functions like you describe. I don’t know why I couldn’t grasp that; I was programming in assembler, too, for crying out loud.

I remember DEF FNxx(y) in the old QuickBasic language, and I never understood it either (I also didn’t know how to program in asm at the time).

---

<div class="post-metadata">

**Author:** ![Superfluous\_Parentheses](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Superfluous\_Parentheses](https://boards.straightdope.com/u/Superfluous_Parentheses)\
**Post date:** [October 6, 2010, 6:46pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/26 "2010-10-06T18:46:57Z")

</div>

> [@BobArrgh](#):
>
> I think it can be argued that some modern programming constructs are actually disguised GOTOs. For example, the “continue” statement placed near the top of a loop indicates that the rest of the loop is to be skipped for that iteration. The code goes back to the the beginning of the loop.
> 
> So, while the GOTO has been denigrated and vilified, its effects are still maintained, albeit in a more-supported fashion.

There’s a lot of GOTO work going on under the hood, but a decently high level language will have the basic abstractions implemented to make direct use of GOTO unnecessary. When you look at optimizing compilers or run times, there’s even more GOTO stuff going on (simple example: tail recursion stack flattening). But a programmer who’s not working on a very low level of abstraction (like, writing assembly, implementing some language runtime, or baking some really interesting new concepts in some hypothetical lisp variant) will not need GOTO. Hell, even C doesn’t have a strict GOTO; setjmp/longjmp are stack based.

---

<div class="post-metadata">

**Author:** ![Simplicio](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Simplicio](https://boards.straightdope.com/u/Simplicio)\
**Post date:** [October 6, 2010, 6:55pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/27 "2010-10-06T18:55:27Z")

</div>

> [@BobArrgh](#):
>
> I think it can be argued that some modern programming constructs are actually disguised GOTOs. For example, the “continue” statement placed near the top of a loop indicates that the rest of the loop is to be skipped for that iteration. The code goes back to the the beginning of the loop.
> 
> So, while the GOTO has been denigrated and vilified, its effects are still maintained, albeit in a more-supported fashion.

IIRC you need GOTO to be a Turing Complete language, so its probably a pretty safe bet that every language will produce GOTOs in the assembler output, even if they don’t have explicit ones in the high level language.

But the point is that GOTOs are low level, and probably don’t belong in high level languages anymore then the ability to address registers do, even though there are plenty of high level commands that are “disguised” register manipulation.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [October 6, 2010, 7:51pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/28 "2010-10-06T19:51:31Z")

</div>

> [@BobArrgh](#):
>
> I think it can be argued that some modern programming constructs are actually disguised GOTOs. For example, the “continue” statement placed near the top of a loop indicates that the rest of the loop is to be skipped for that iteration. The code goes back to the the beginning of the loop.
> 
> So, while the GOTO has been denigrated and vilified, its effects are still maintained, albeit in a more-supported fashion.

True. You can avoid the use of such constructs by using flags - if you find a situation where you actually want to continue, set the flag and don’t do anything if the flag is set during the rest of the loop - but what you wind up with is even worse than using a go to. Pascal had this problem. This was exactly what the orals question I mentioned above was about. But loop exit statements are very constrained as to destination, with labels only necessary if you want to exit from several layers down.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [October 6, 2010, 7:54pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/29 "2010-10-06T19:54:57Z")

</div>

> [@Simplicio](#):
>
> IIRC you need GOTO to be a Turing Complete language, so its probably a pretty safe bet that every language will produce GOTOs in the assembler output, even if they don’t have explicit ones in the high level language.

A very safe bet, since you cannot implement the control blocks that are a part of any high level language without them. I include conditional branches as case of gotos. Jumps just change the contents of the program counter - kind of hard to do much without being able to do that.

---

<div class="post-metadata">

**Author:** ![Rysto](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Rysto](https://boards.straightdope.com/u/Rysto)\
**Post date:** [October 6, 2010, 8:06pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/30 "2010-10-06T20:06:52Z")

</div>

> [@Simplicio](#):
>
> IIRC you need GOTO to be a Turing Complete language, so its probably a pretty safe bet that every language will produce GOTOs in the assembler output, even if they don’t have explicit ones in the high level language.

Not really. The lambda calculus doesn’t have anything that resembles a “goto” statement, and it’s Turing Complete.

---

<div class="post-metadata">

**Author:** ![RaftPeople](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RaftPeople](https://boards.straightdope.com/u/RaftPeople)\
**Post date:** [October 6, 2010, 8:24pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/31 "2010-10-06T20:24:47Z")

</div>

> [@Voyager](#):
>
> > [@BobArrgh](#):
> >
> > I think it can be argued that some modern programming constructs are actually disguised GOTOs. For example, the “continue” statement placed near the top of a loop indicates that the rest of the loop is to be skipped for that iteration. The code goes back to the the beginning of the loop.
> > 
> > So, while the GOTO has been denigrated and vilified, its effects are still maintained, albeit in a more-supported fashion.
> 
> True. You can avoid the use of such constructs by using flags - if you find a situation where you actually want to continue, set the flag and don’t do anything if the flag is set during the rest of the loop - but what you wind up with is even worse than using a go to. Pascal had this problem. This was exactly what the orals question I mentioned above was about. But loop exit statements are very constrained as to destination, with labels only necessary if you want to exit from several layers down.

This is exactly correct.

I could write perfectly beautiful code with just GOTO’s, the issue isn’t the actual function of jumping control to a different portion of code - it’s the overall organization of the code, the number of entries and exits to sections of code, the independence of function, etc.

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [October 6, 2010, 8:35pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/32 "2010-10-06T20:35:25Z")

</div>

I’ve been a professional C programmer for 15 years, and I can think of only two cases where I used GOTOs, and both involved cases where performance was paramount:

(1) a very tricky piece of code that was decoding RLE graphics of some sort, which was basically jumping between 6 or 7 FSMs each of which would grab the next bit of data and process it. So basically like 6 or 7 switch statements all in one function, each one with a label before it, with many of the cases being GOTOs to the labels. Could have been one larger level switch statement with a state variable, but that would have been slightly less optimized

(2) a multiply nested loop in which the GOTO was basically break, and only GOTO’d a label directly after the loop

---

<div class="post-metadata">

**Author:** ![Rysto](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Rysto](https://boards.straightdope.com/u/Rysto)\
**Post date:** [October 6, 2010, 9:04pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/33 "2010-10-06T21:04:00Z")

</div>

I’m a C programmer, and I use goto all of the time. It’s often the only sane way to handle errors in C.

Outside of error handling and multi-level breaks I would never use it.

---

<div class="post-metadata">

**Author:** ![Otara](https://avatars.discourse-cdn.com/v4/letter/o/a88e4f/32.png) [@Otara](https://boards.straightdope.com/u/Otara)\
**Post date:** [October 6, 2010, 9:04pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/34 "2010-10-06T21:04:21Z")

</div>

> [@Enright3](#):
>
> So was I. Those were good days to be working for a major airline (American).  
> Younger programmers today can’t fathom writing a program and keeping it within a 1K block. When things advanced far enough for us to get 4K blocks we didn’t know what to do with ourselves.

Heh well I was spoilt and only ever had to worry about 4k. Which as you say always seemed like plenty.

Otara

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [October 6, 2010, 9:07pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/35 "2010-10-06T21:07:06Z")

</div>

> [@RaftPeople](#):
>
> I could write perfectly beautiful code with just GOTO’s, the issue isn’t the actual function of jumping control to a different portion of code - it’s the overall organization of the code, the number of entries and exits to sections of code, the independence of function, etc.

This is exactly what we were trying to teach our assembly language class. We did a fairly good job of it. It isn’t hard once you incorporate it into your programming style. In one quiz section I was teaching I for some reason wrote a recursive factorial program in PDP-11 assembly language on the fly in front of the class. You can’t do that unless you think in terms of high level constructs first.

People used to call programs with lots of gotos spaghetti code. I was working for AT&T when we released our first PC, made by Olivetti. One guy called it the pasta processor, great for running spaghetti code.

---

<div class="post-metadata">

**Author:** ![jasg](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@jasg](https://boards.straightdope.com/u/jasg)\
**Post date:** [October 6, 2010, 9:33pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/36 "2010-10-06T21:33:34Z")

</div>

> [@Robot\_Arm](#):
>
> Do you have an opinion on the COME FROM statement?

I was and advocate for that and the IF-THEN-MAYBE construct as extensions to the language [Babbage](http://www.tlc-systems.com/babbage.htm). Sadly, that language never really became popular…

---

<div class="post-metadata">

**Author:** ![Muffin](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/muffin/32/4341_2.png) [@Muffin](https://boards.straightdope.com/u/Muffin)\
**Post date:** [October 6, 2010, 10:36pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/37 "2010-10-06T22:36:20Z")

</div>

> [@jasg](#):
>
> I was and advocate for that and the IF-THEN-MAYBE construct as extensions to the language [Babbage](http://www.tlc-systems.com/babbage.htm). Sadly, that language never really became popular…

Sweet!

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [October 6, 2010, 11:33pm UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/38 "2010-10-06T23:33:42Z")

</div>

> [@jasg](#):
>
> > [@Robot\_Arm](#):
> >
> > Do you have an opinion on the COME FROM statement?
> 
> I was and advocate for that and the IF-THEN-MAYBE construct as extensions to the language [Babbage](http://www.tlc-systems.com/babbage.htm). Sadly, that language never really became popular…

Know ye of [INTERCAL](http://www.catb.org/esr/intercal/stross.html)?

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [October 7, 2010, 6:31am UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/39 "2010-10-07T06:31:25Z")

</div>

> [@jasg](#):
>
> > [@Robot\_Arm](#):
> >
> > Do you have an opinion on the COME FROM statement?
> 
> I was and advocate for that and the IF-THEN-MAYBE construct as extensions to the language [Babbage](http://www.tlc-systems.com/babbage.htm). Sadly, that language never really became popular…

I actually remember that article - I was reading Datamation back then.

There was also a set of recommended IBM 360 instructions like this, including my favorite, RPM (Read Programmer’s Mind). I can’t find them with a quick search, though.

---

<div class="post-metadata">

**Author:** ![Capt.Ridley\_s\_Shooting\_Party](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Capt.Ridley\_s\_Shooting\_Party](https://boards.straightdope.com/u/Capt.Ridley_s_Shooting_Party)\
**Post date:** [October 7, 2010, 9:50am UTC](https://boards.straightdope.com/t/goto-lazy-programming/556186/40 "2010-10-07T09:50:41Z")

</div>

> [@BobArrgh](#):
>
> I think it can be argued that some modern programming constructs are actually disguised GOTOs. For example, the “continue” statement placed near the top of a loop indicates that the rest of the loop is to be skipped for that iteration. The code goes back to the the beginning of the loop.
> 
> So, while the GOTO has been denigrated and vilified, its effects are still maintained, albeit in a more-supported fashion.

Continuation passing style seems to me to have all the disadvantages of goto. It’s inexplicably also extremely popular with functional programmers.

[QUOTE=Simplicio]

IIRC you need GOTO to be a Turing Complete language, so its probably a pretty safe bet that every language will produce GOTOs in the assembler output, even if they don’t have explicit ones in the high level language.

[/quote]

You need unbounded iteration (or recursion) and the ability to control the flow of the program. You don’t need goto to do the latter, and if statement (much more circumscripted than a goto) will work.

[Previous page](https://boards.straightdope.com/t/goto-lazy-programming/556186.md?page=1)

[Next page](https://boards.straightdope.com/t/goto-lazy-programming/556186.md?page=3)
