go_to what's in using them

M

marora

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

Can any one here shed some light?

Thanks in advance,
Manish
 
W

Walter Roberson

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?
Can any one here shed some light?

You may wish to search out the famous article,
"Go To Statement Considered Harmful" by Dijkstra.
 
L

Lew Pitcher

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

Can any one here shed some light?

See the Wirth article referenced elsethread.

To summarize:
a) the biggest cost in development is the cost of the programmer.
b) programmers spend more time debugging and maintaining existing code
than developing new code
c) the use of "goto" complicates code maintenance as it increases the
number of logic paths, while providing little or no visual guidance to
the maintenance programmer
d) thus causing the programmer to spend more time and energy
understanding the existing logic and developing suitable new logic that
will not conflict with the existing goto statements,
e) thus causing an unnecessary inflation of development time and costs
f) Also, the use of "goto" complicates code debugging as it leaves no
trail to backtrace from,
g) thus causing the programmer to spend more time and energy searching
for possible hidden logic paths that lead to the abnormal condition,
h) thus causing an unnecessary inflation of debugging time and costs

On the other hand, gotoless programming leaves the code in an easily
readable state in which all logic paths are clearly delimited. Thus
development and maintenance programmers spend less time trying to
understand the code, which keeps development costs (time and money)
down.

HTH
 
C

Charles Richmond

Walter said:
You may wish to search out the famous article,
"Go To Statement Considered Harmful" by Dijkstra.
Me thinks he first needs to read "Trolling Considered Harmful".
 
R

Richard Heathfield

(e-mail address removed) said:
I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

There isn't any reason not to use go_to in your code. Observe:

#include <stdio.h>

int main(void)
{
int go_to = 6;

printf("%d\n", go_to);

return 0;
}

This is perfectly legal, clear, readable C.
Can any one here shed some light?

More than you can possibly imagine.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
C

Coos Haak

Op 9 Nov 2006 11:35:53 -0800 schreef Lew Pitcher:
Sorry, I meant Dyjkstra, not Wirth

Dutch spelling is obviously difficult:
Dijkstra, where ij was formerly regarded as one letter, sharing the same
part of the dictionary with y.
See also: IJsselmeer, IJsland. Not in Belgium, there they write Ijsselmeer
and Ijsland.
 
C

Chris Dollin

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

`goto`, not `go_to`.

Roughly: using goto means that the structure of your code needs
to be unscrambled by connecting the gotos (the goestos?) to the
corresponding label. This is tedious and prone to error when the
code changes [1]. /Usually/, the syntactically obvious control
structures -- if, while, for, switch, the humble semicolon -- will
do a perfectly good job of expressing structure, and with the
addition of the slightly edgy `break`, `continue`, and `return`,
you're covered for most things you'll meet in practice.

/Sometimes/ those control structures won't do the job well
enough -- for example in a error situation when you're faced
with Standard Situation N [2] -- and then a goto or two
may be the clearest way to solve the problem. (Think of this
as hand-implementing the try-catch construct C doesn't have,
more so if you use setjmp/longjmp in place of goto). But if the
situation doesn't require it, don't use it, otherwise you'll
mislead the reader into thinking either that they've missed
something, or that /you/ have.

Peeking at my interpreter code here, I see that `goto` appears
in:

(a) generated code from flex & bison, so that doesn't count
(any more than the branches and jumps in compiled code do)

(b) in /one/ other module, where it's part of the error recovery
code in a bytecode [3] interpreter: when assorted operations
break (eg trying to add a string to an integer) then control
has to pass to a place where the interpreter can implement
"throw an exception".

Otherwise there's no gotos. (This is about 20K lines of commented
non-header code, not big but hardly trivial.) But I do use
`return` not at the bottom of a function, and `break` to get out
of loops from time to time, although that's mostly for finishing
a switch-case: if I were in a bad mood, I might count those as
gotos. I don't seem to have used `continue` at all ...
Can any one here shed some light?

Heat is, alas, more likely for this subject.

[1] Rule X: the code will have to change, /especially/ the code
for which there are promises signed in blood that it will
never change.

[2] When the only important thing is to get out, and get out NOW.

[3] For values of `byte` that are `short`.
 
R

Richard Bos

Coos Haak said:
Op 9 Nov 2006 11:35:53 -0800 schreef Lew Pitcher:

And while you want to read that article, you also want to take it with
the knowledge in mind that it was a polemic, intended as part of a
discussion between two camps of Cleans and Scruffies. Guess which camp
Dijkstra was in? The result is that while he states his case well, he
overstates it. One should be very wary about using goto. Most people
won't need it more than a couple of times in their programming lives.
But if you happen to write state machines, parsers, or what have you, it
may be a regular part of the best solution.
Dutch spelling is obviously difficult:
Dijkstra, where ij was formerly regarded as one letter, sharing the same
part of the dictionary with y.
See also: IJsselmeer, IJsland. Not in Belgium, there they write Ijsselmeer
and Ijsland.

Yeah, but they're Belgians. Dey know nuthin'.

Richard
 
E

Ed Prochak

Lew said:
See the Wirth article referenced elsethread.

Wirth was also a Structured programming advocate.
To summarize:
a) the biggest cost in development is the cost of the programmer.
b) programmers spend more time debugging and maintaining existing code
than developing new code
c) the use of "goto" complicates code maintenance as it increases the
number of logic paths, while providing little or no visual guidance to
the maintenance programmer
d) thus causing the programmer to spend more time and energy
understanding the existing logic and developing suitable new logic that
will not conflict with the existing goto statements,
e) thus causing an unnecessary inflation of development time and costs
f) Also, the use of "goto" complicates code debugging as it leaves no
trail to backtrace from,
g) thus causing the programmer to spend more time and energy searching
for possible hidden logic paths that lead to the abnormal condition,
h) thus causing an unnecessary inflation of debugging time and costs

On the other hand, gotoless programming leaves the code in an easily
readable state in which all logic paths are clearly delimited. Thus
development and maintenance programmers spend less time trying to
understand the code, which keeps development costs (time and money)
down.

HTH

However even Wirth did not propose complete elimination of GOTO. Wirth
created PASCAL and still included GOTO. His chief use of GOTO was error
handling. The goal of the Structured Programming movement is often
mistakenly described as seaking GOTOless programming. Such a
description is wrong. It was the UNRESTRAINED use of goto that they
sought to eliminate.

Sadly goto might be gone in many modern OO languangues, but also gone
is any sense of readability.

Ed
 
R

Richard Tobin

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?
[/QUOTE]
There isn't any reason not to use go_to in your code.

Likewise, there isn't any reason not to use to_go in your code, but
using togo results in undefined behaviour.

-- Richard
 
W

Walter Roberson

Ed Prochak said:
However even Wirth did not propose complete elimination of GOTO. Wirth
created PASCAL and still included GOTO. His chief use of GOTO was error
handling. The goal of the Structured Programming movement is often
mistakenly described as seaking GOTOless programming. Such a
description is wrong. It was the UNRESTRAINED use of goto that they
sought to eliminate.

Your analysis disagrees with Wirth's own published works.

http://www.swissdelphicenter.ch/en/niklauswirth.php

Yet, Pascal also suffered from certain deficiencies, more or
less significant depending on personal perception and
application. [...]

Certain other deficiencies were due to the author's lack of
courage to throw some rules inherited from Algol over board, in
fear of antagonizing influential Algol programmers. The prime
entry in this list is the famed go to statement, retained
although, in principle, always replaceable by an if, while, or
repeat construct
 
R

Richard Tobin

Walter Roberson said:
Your analysis disagrees with Wirth's own published works.

No doubt Ed's charitable nature led him to replace Wirth's absurd
view with a more reasonable one.
The prime
entry in this list is the famed go to statement, retained
although, in principle, always replaceable by an if, while, or
repeat construct

The while and repeat constructs can always be replaced by if and goto,
yet remarkably few languages have removed them. Of all the arguments
against goto, this is the most wirthless.

-- Richard
 
A

av

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

`goto`, not `go_to`.

Roughly: using goto means that the structure of your code needs
to be unscrambled by connecting the gotos (the goestos?) to the
corresponding label. This is tedious and prone to error when the
code changes [1]. /Usually/, the syntactically obvious control

bla, bla, bla
you and all ng is wrong on "goto"
because you all seems don't know how that instruction (and labels)
have to appear in the page (or in the screen).

in the first it was "goto" instruction :)
 
B

Bill Pursell

av said:
I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

`goto`, not `go_to`.

Roughly: using goto means that the structure of your code needs
to be unscrambled by connecting the gotos (the goestos?) to the
corresponding label. This is tedious and prone to error when the
code changes [1]. /Usually/, the syntactically obvious control

bla, bla, bla
you and all ng is wrong on "goto"
because you all seems don't know how that instruction (and labels)
have to appear in the page (or in the screen).

Huh? Not everyone reading the newsgroup thinks that goto
is horrible. Several people have alluded to that in this thread.
Many people think it's a pointless religious war.

As to your point that having the label on screen makes
code readable, consider:

int
main(void)
{

int x; x = 1; goto a; a:x -= 5; b:goto e; c:x += 4;
d:goto h; e:x -= 3; f:goto c; g:x *= 2; h:goto i;
i:x -= 1; printf("%d\n", x); return 0; goto g;
goto g; goto f; goto b; goto d;

}
 
A

av

av said:
(e-mail address removed) wrote:

I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

`goto`, not `go_to`.

Roughly: using goto means that the structure of your code needs
to be unscrambled by connecting the gotos (the goestos?) to the
corresponding label. This is tedious and prone to error when the
code changes [1]. /Usually/, the syntactically obvious control

bla, bla, bla
you and all ng is wrong on "goto"
because you all seems don't know how that instruction (and labels)
have to appear in the page (or in the screen).

Huh? Not everyone reading the newsgroup thinks that goto
is horrible. Several people have alluded to that in this thread.
Many people think it's a pointless religious war.

As to your point that having the label on screen makes
code readable, consider:

int
main(void)
{

int x; x = 1; goto a; a:x -= 5; b:goto e; c:x += 4;
d:goto h; e:x -= 3; f:goto c; g:x *= 2; h:goto i;
i:x -= 1; printf("%d\n", x); return 0; goto g;
goto g; goto f; goto b; goto d;

}

the above is the classical example on how not to use goto

if you understand me,
and you want i have some difficulties just post some c code
that not use goto and claim that solution is the best possible
and no goto can make better that code

possobily i rewrite that code better with only(no if, while, for)
use of goto
 
G

Guest

av said:
av said:
I keep hearing about not to use 'go_to' in your code. However, I don't
know what's the reasoning behind it?

`goto`, not `go_to`.

Roughly: using goto means that the structure of your code needs
to be unscrambled by connecting the gotos (the goestos?) to the
corresponding label. This is tedious and prone to error when the
code changes [1]. /Usually/, the syntactically obvious control

bla, bla, bla
you and all ng is wrong on "goto"
because you all seems don't know how that instruction (and labels)
have to appear in the page (or in the screen).

Huh? Not everyone reading the newsgroup thinks that goto
is horrible. Several people have alluded to that in this thread.
Many people think it's a pointless religious war.

As to your point that having the label on screen makes
code readable, consider:

int
main(void)
{

int x; x = 1; goto a; a:x -= 5; b:goto e; c:x += 4;
d:goto h; e:x -= 3; f:goto c; g:x *= 2; h:goto i;
i:x -= 1; printf("%d\n", x); return 0; goto g;
goto g; goto f; goto b; goto d;

}

the above is the classical example on how not to use goto

if you understand me,
and you want i have some difficulties just post some c code
that not use goto and claim that solution is the best possible
and no goto can make better that code

possobily i rewrite that code better with only(no if, while, for)
use of goto

And very likely, your rewrite of that code would also be a classical
example on how not to use goto.
 
S

santosh

av said:
"while, for, ifs Statements Considered Harmful" by me :)

Are you 'ab' of alt.lang.asm? If so, seemingly, you don't like
traditional assembler nor do you like C! Maybe you should start a group
for your private language, tons of whose source you regularly spam
a.l.a with...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top