473,769 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

go_to what's in using them

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

Nov 9 '06 #1
23 1789
In article <11************ **********@h48g 2000cwc.googleg roups.com>,
ma****@gmail.co m <ma****@gmail.c omwrote:
>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.
--
All is vanity. -- Ecclesiastes
Nov 9 '06 #2

ma****@gmail.co m wrote:
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
--
Lew

Nov 9 '06 #3

Lew Pitcher wrote:
ma****@gmail.co m wrote:
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.
Sorry, I meant Dyjkstra, not Wirth

Nov 9 '06 #4
Walter Roberson wrote:
>
In article <11************ **********@h48g 2000cwc.googleg roups.com>,
ma****@gmail.co m <ma****@gmail.c omwrote:
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.
Me thinks he first needs to read "Trolling Considered Harmful".

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
Nov 9 '06 #5
ma****@gmail.co m 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.
Nov 9 '06 #6
Op 9 Nov 2006 11:35:53 -0800 schreef Lew Pitcher:
Lew Pitcher wrote:
>ma****@gmail.co m wrote:
>>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.

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.
--
Coos
Nov 10 '06 #7
ma****@gmail.co m 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
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`.

--
Chris "spinning dizzily" Dollin
Scoring, bah. If I want scoring I'll go play /Age of Steam/.

Nov 10 '06 #8
Coos Haak <ch*****@hccnet .nlwrote:
Op 9 Nov 2006 11:35:53 -0800 schreef Lew Pitcher:
Lew Pitcher wrote:
ma****@gmail.co m wrote:
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.
Sorry, I meant Dyjkstra, not Wirth
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
Nov 10 '06 #9

Lew Pitcher wrote:
ma****@gmail.co m wrote:
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.
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
--
Lew
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

Nov 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
6576
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
92
6530
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption? cheers, reed
137
7174
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very pragmatic - 3) I usually move forward when I get the gut feeling I am correct - 4) Most likely because of 1), I usually do not manage to fully explain 3) when it comes true. - 5) I have developed for many years (>18) in many different environments,...
125
14843
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
121
10164
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
9
2221
by: Patty O'Dors | last post by:
Hi Can somebody please tell me what namespaces are actually for? I notice that when I start a new project in C#, it puts everything in a namespace of the same name as the project. I found them a bit annoying as when I save a class's .cs file to my 'generic code' folder, and then put it in another project, I have to manually go and change the namespace name. This I find a bit of a PITA. I used VB.NET for a bit and found it didn't have...
13
5058
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
669
26191
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
8
2007
by: clintonG | last post by:
Every single time neophytes or converts ask about naming and style conventions what are they told by the majority consensus? The answer is "do what you prefer but do so consistently" right? Yes, that's right, that's exactly what is said. People joining a team of developers are also encouraged to cooperate with their peers and adopt what has already been established right? Yes, that's exactly what is encouraged. Teamwork and cooperation...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10036
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.