I really love the "goto" statement.

I really love the "goto" statement.

Post by Ruediger R. Asch » Wed, 17 Jan 2001 18:32:41



hmpfh, isn't there a newsgroup on goto somewhere out in the world?

I don't think there's any significant new contribution to that issue - it's
been discussed to death already, but maybe this aspect hasn't been looked at
a whole lot nevertheless:

In terms of expressive power, goto and all of the other control structures
are equivalent - in fact, the notion of "continuation" is the most generic,
allowing to abstract away not only goto, while, do and if (those are very
easy to identify as equivalent if you look at the generated assembly code)
but also recursion and iteration. Programming languages that provides
continuations as primitives (such as Scheme) don't really need anything else
(there is an if as a primitive in Scheme, but I think somebody has shown
that you don't really need it as long as there are continuation objects).

Thus, the discussion about "is goto bad or not" is not even academic. In my
experience coding in C, there is justification for goto in many cases if the
underlying OS does not support structured exception handling - for example,
if within a function body, there are several error exits in which you need
to clean up resources to various degrees - without SEH and goto, you would
need to repeat code in several places, thus obstructing code and introducing
many subtle cases of errors.



Quote:> Today's  development favors "no goto",  and  I think the reason it came
> about is :
> ---------------------------------------------------

> Many years ago, the main programming languages were COBOL, FORTRAN. At
that
> time, "if" statement was very simple, e.g. in Fortran, the if-statement is

>         if (....) goto ....

> Hence people must use lots of "goto". This, coupled with the fact that
> labels do not have to be consecutive, (FORTRAN) e.g.

>         1000  .....
>               if (....) goto 20

>          700  .......
>               .......
>               if (....) goto 300
>               ......
>         5000  ......
>               .....
>           60  .....

>           ...............

> people really had a difficult time to trace programs.

> Some computer scientists found that, if we introduce constructs like
(Qbasic
> constructs)

> while ... wend
> do .... loop while ....
> do .... loop until ....
> do while ..... loop
> do until ..... loop
> select case .... end select

> we can do away with "goto", hence goes the confusion as well.

> But now one has to learn a lot of constructs, instead of learning one
simple
> "goto".

> Was the situation really that bad in the old times? Not so. Programmers
have
> long discovered some "good programming habits". Consider the following
piece
> of (FORTRAN) code :

>             if ( .not. condition1) goto 200
>                    ......
>                    ......
>                    ......
>             goto 1000

>        200  if ( .not. condition2) goto 400
>                    ......
>                    ......
>                    ......
>             goto 1000

>        400  if ( .not. condition3) goto 600
>                    ......
>                    ......
>                    ......
>             goto 1000

>        600  if ( .not. condition4) goto 800
>                    ......
>                    ......
>                    ......
>             goto 1000

>        800  if ( .not. condition5) goto 1000
>                    ......
>                    ......

>       1000   .........

> Moreover, labels are strictly in ascending order. As you can see, the
above
> coding is very clear in its intent, and, in my opinion, is in fact much
> better than the "no goto" but levels upon levels of nested "if" statements
> common nowadays.

> Now people introduce something like "break LABEL" or "break No-of-levels"
> ....

> Why not use the "goto" instead?

 
 
 

I really love the "goto" statement.

Post by Nick Hristo » Wed, 17 Jan 2001 06:18:42


I believe the "goto" statement went out because of a different and more
subtle reason that simply "bad looking code"...

The main problem is that with goto you can not make any real
code-reusability, as you can do with functional languages... yes, you can
"call" different sections of your code, however, if you want to have a
proper return the section of code that "called" the "goto" statement, you
are going to have a problem. There is a way to do it, but it is ugly,
insufficient and most importantly unscalable.

Nick

Quote:>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<


I really love the "goto" statement.:

Quote:> Today's  development favors "no goto",  and  I think the reason it came
> about is :
> ---------------------------------------------------
> Many years ago, the main programming languages were COBOL, FORTRAN. At
that
> time, "if" statement was very simple, e.g. in Fortran, the if-statement

is

Quote:>         if (....) goto ....
> Hence people must use lots of "goto". This, coupled with the fact that
> labels do not have to be consecutive, (FORTRAN) e.g.
>         1000  .....
>               if (....) goto 20
>          700  .......
>               .......
>               if (....) goto 300
>               ......
>         5000  ......
>               .....
>           60  .....
>           ...............
> people really had a difficult time to trace programs.
> Some computer scientists found that, if we introduce constructs like
(Qbasic
> constructs)
> while ... wend
> do .... loop while ....
> do .... loop until ....
> do while ..... loop
> do until ..... loop
> select case .... end select
> we can do away with "goto", hence goes the confusion as well.
> But now one has to learn a lot of constructs, instead of learning one
simple
> "goto".
> Was the situation really that bad in the old times? Not so. Programmers
have
> long discovered some "good programming habits". Consider the following
piece
> of (FORTRAN) code :
>             if ( .not. condition1) goto 200
>                    ......
>                    ......
>                    ......
>             goto 1000
>        200  if ( .not. condition2) goto 400
>                    ......
>                    ......
>                    ......
>             goto 1000
>        400  if ( .not. condition3) goto 600
>                    ......
>                    ......
>                    ......
>             goto 1000
>        600  if ( .not. condition4) goto 800
>                    ......
>                    ......
>                    ......
>             goto 1000
>        800  if ( .not. condition5) goto 1000
>                    ......
>                    ......
>       1000   .........
> Moreover, labels are strictly in ascending order. As you can see, the
above
> coding is very clear in its intent, and, in my opinion, is in fact much
> better than the "no goto" but levels upon levels of nested "if"
statements
> common nowadays.
> Now people introduce something like "break LABEL" or "break No-of-levels"
> ....
> Why not use the "goto" instead?


 
 
 

I really love the "goto" statement.

Post by Andrew Gabri » Wed, 17 Jan 2001 23:33:21


A long-standing colleague of mine, who has spent much of his
programming time writing the microcode embedded in micro-programmed
processors, when criticised for his liberal use of goto's, responds:

"When the compiler stops laying down branch instructions, I'll stop
using goto's" :-)

--
Andrew Gabriel

 
 
 

I really love the "goto" statement.

Post by Russ Bix » Thu, 18 Jan 2001 03:53:12



<gotos are good part snipped>

Gotos are not inherrently bad, but it's easier to shoot oneself in the foot
with them and they don't really allow for recursion, rentrancy and structured
programming.

Of course, processors themselves are not procedural - in assembly language
it's all ifs and gotos, but higher level languages are just that - higher
level.

The fastest languages are not procedural at all - they use gotos and old
fashioned constructs and are still used primarily because they are fast or
because they do one thing exceptionally well.

In the world of "get it out the door yesterday," however, we must have tools
with some degree of foot-shot avoidance.  That's why I really like Ada, but
I fear I'm in the minority on that one.

When programming with switches and plugboards, I used very few case statements
or while loops, but I do like them.  BTW, calling while loops "qBasic like" is
like calling the Macintosh "Windows like;"  precedence is important, fella.

The "gotos are bad" school of thought, I feel, would do well to reform into
the "lazy programmers should be shot" school.

Narf,

Russ Bixby, geek at large

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 
 
 

I really love the "goto" statement.

Post by Peter S Tillie » Thu, 18 Jan 2001 19:51:43




<snip>

Quote:> Why not use the "goto" instead?

If you relay like "GOTO" you'll love Intercal's "COME FROM" - a much more
interesting statement.  Try a search for Intercal.

--
Peter S Tillier

Usual disclaimers, E&OE

 
 
 

I really love the "goto" statement.

Post by Andrew Giert » Thu, 18 Jan 2001 20:16:56


 Peter> If you relay like "GOTO" you'll love Intercal's "COME FROM" -
 Peter> a much more interesting statement.

Especially in Threaded Intercal.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

I really love the "goto" statement.

Post by Toby Thai » Fri, 19 Jan 2001 19:52:44



> ...
> If you relay like "GOTO" you'll love Intercal's "COME FROM" - a much more
> interesting statement.  Try a search for Intercal.

Touche!

Next, someone will propose we all go back to coding in assembler.

(BTW I feel bound to speak up in defense of the cascaded if - one of my
favourite goto-less HLL idioms.)

T