Hi,
Is it good practice using GOTO in .NET application?
Please advice.
Thanks, Kartic 13 8405
I'm not religious about it, although I don't have a single GOTO in over
50,000 lines of code in my project. It isn't neccessary. But if you feel
the need, be my guest ;)
"Kartic" <kg****@csystemssoftware.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl... Hi, Is it good practice using GOTO in .NET application?
Please advice. Thanks, Kartic
Hi Kartic,
Is this serious or do you want to build a long thread in this newsgroup.
The answer is No.
Cor
Kartic:
There are a few situations where Goto may be the best solution, like in a
switch statement where you want to simulate fall-through. However, those
situations are Rare indeed and I can count them on my hand. The real
problem with Goto is that people overuse them and use them as slopppy
shortcuts. Like Robin, I think in about 60,000 lines of code, I don't think
I've ever needed to use one, and prefer not to. And my examples of
Fall-through is related to C# mainly and only deals with switch statements.
Basically, the answer is No, don't use it. If you are absolutely sure that
using GoTo is the most effecitve way to do something, then go ahead, but
limit it's use as much as possible and make sure you have a very compelling
reason to use it. And if your program uses it more than once or twice in
rare occassions, you are already overusing it.
I'm not religious about it either, I just don't see much of a need for it...
and I've seen a lot more damage done with it than good come from it.
"Kartic" <kg****@csystemssoftware.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl... Hi, Is it good practice using GOTO in .NET application?
Please advice. Thanks, Kartic
Kartic,
As the others suggest, most developers feel using GOTO is not a good
practice in any language!
However! using GOTO is useful sometimes.
One place I see value is a Try/Catch block to allow retrying a statement,
something like:
Try
TRYAGAIN:
AttemptToReadFile()
' Throw New System.IO.FileNotFoundException
Catch ex As System.IO.FileNotFoundException
If MessageBox.Show("What would you like to do?", "File not
found", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = DialogResult.Retry Then
GoTo TRYAGAIN
Else
Throw ' let error propagate up
End If
End Try
Where the AttemptToReadFile method opens a file and attempts to read it, if
the file is not found, a dialog is shown to the user, and the Goto allows
the program to try the AttemptToReadFile a second time. I would only handle
specific exceptions this way, for example FileNotFoundException instead of
System.Exception.
Another place I see value is in complicated loops, within loops, when you
need to get out of an inner most loop, back to the outer most loop quickly,
however I attempt to avoid nesting loops (directly) too much...
Hope this helps
Jay
"Kartic" <kg****@csystemssoftware.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl... Hi, Is it good practice using GOTO in .NET application?
Please advice. Thanks, Kartic
Yes, the second example is one I've come across a lot in my code. Instead
of using the GOTO, I tend to use a boolean flag to tell me when to break out
of the loop. Actually, in this case, I would hardly say it was easier to
read or understand the flow of code, but I've just become used to doing
things like this rather than using gotos'.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl... Kartic, As the others suggest, most developers feel using GOTO is not a good practice in any language!
However! using GOTO is useful sometimes.
One place I see value is a Try/Catch block to allow retrying a statement, something like:
Try TRYAGAIN: AttemptToReadFile() ' Throw New System.IO.FileNotFoundException Catch ex As System.IO.FileNotFoundException If MessageBox.Show("What would you like to do?", "File not found", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Retry Then GoTo TRYAGAIN Else Throw ' let error propagate up End If End Try
Where the AttemptToReadFile method opens a file and attempts to read it,
if the file is not found, a dialog is shown to the user, and the Goto allows the program to try the AttemptToReadFile a second time. I would only
handle specific exceptions this way, for example FileNotFoundException instead of System.Exception.
Another place I see value is in complicated loops, within loops, when you need to get out of an inner most loop, back to the outer most loop
quickly, however I attempt to avoid nesting loops (directly) too much...
Hope this helps Jay
"Kartic" <kg****@csystemssoftware.com> wrote in message news:uC**************@TK2MSFTNGP12.phx.gbl... Hi, Is it good practice using GOTO in .NET application?
Please advice. Thanks, Kartic
Robin,
Agreed.
I would consider the Boolean over the Goto, until the Boolean was
complicating & convoluting the code too much... In that there is stuff after
the inner loops that need to be skipped, so you have to include the Boolean
on each loop, then you need if statements that check the Boolean, then you
need...
Remember bad use of a Goto does not make the Goto bad!
Too many developers think Goto is Bad! as they have seen bad uses of Goto
too often...
Jay
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c6*******************@news.demon.co.uk... Yes, the second example is one I've come across a lot in my code. Instead of using the GOTO, I tend to use a boolean flag to tell me when to break
out of the loop. Actually, in this case, I would hardly say it was easier to read or understand the flow of code, but I've just become used to doing things like this rather than using gotos'.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eC**************@TK2MSFTNGP12.phx.gbl... Kartic, As the others suggest, most developers feel using GOTO is not a good practice in any language!
However! using GOTO is useful sometimes.
One place I see value is a Try/Catch block to allow retrying a
statement, something like:
Try TRYAGAIN: AttemptToReadFile() ' Throw New System.IO.FileNotFoundException Catch ex As System.IO.FileNotFoundException If MessageBox.Show("What would you like to do?", "File not found", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Retry Then GoTo TRYAGAIN Else Throw ' let error propagate up End If End Try
Where the AttemptToReadFile method opens a file and attempts to read it, if the file is not found, a dialog is shown to the user, and the Goto
allows the program to try the AttemptToReadFile a second time. I would only handle specific exceptions this way, for example FileNotFoundException instead
of System.Exception.
Another place I see value is in complicated loops, within loops, when
you need to get out of an inner most loop, back to the outer most loop quickly, however I attempt to avoid nesting loops (directly) too much...
Hope this helps Jay
"Kartic" <kg****@csystemssoftware.com> wrote in message news:uC**************@TK2MSFTNGP12.phx.gbl... Hi, Is it good practice using GOTO in .NET application?
Please advice. Thanks, Kartic
Cor,
First a question: Why are you attempting to build a long thread? ;-)
As I told Robin:
Remember bad use of a Goto does not make the Goto bad!
Too many developers think Goto is Bad! as they have seen bad uses of Goto
too often...
The second link is interesting, I don't see what you are trying to say with
the first (other then who wrote the second).
Just a thought
Jay
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:e%****************@TK2MSFTNGP11.phx.gbl... Hi Jay B. (And Bill)
I never come with documents, however this greath Dutchman will turn around about your writting.
(He has done very much for modern programming, in my idea most modern languages derives partialy from his ideas)
http://www.cs.utexas.edu/users/EWD/
http://www.acm.org/classics/oct95/
Cor
I think though, if I remember my formal specification classes, that using
GOTOs does tend to mess up any mathematical description of your process (not
that we tend to design our applications in "Z" before implementing them in
VB!).
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... Cor, First a question: Why are you attempting to build a long thread? ;-)
As I told Robin:
Remember bad use of a Goto does not make the Goto bad!
Too many developers think Goto is Bad! as they have seen bad uses of Goto too often...
The second link is interesting, I don't see what you are trying to say
with the first (other then who wrote the second).
Just a thought Jay
"Cor Ligthert" <no**********@planet.nl> wrote in message news:e%****************@TK2MSFTNGP11.phx.gbl... Hi Jay B. (And Bill)
I never come with documents, however this greath Dutchman will turn
around about your writting.
(He has done very much for modern programming, in my idea most modern languages derives partialy from his ideas)
http://www.cs.utexas.edu/users/EWD/
http://www.acm.org/classics/oct95/
Cor
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl... Cor, First a question: Why are you attempting to build a long thread? ;-)
It's been awhile... =) As I told Robin:
Remember bad use of a Goto does not make the Goto bad!
Too many developers think Goto is Bad! as they have seen bad uses of Goto too often...
The second link is interesting, I don't see what you are trying to say
with the first (other then who wrote the second).
Just a thought Jay
"Cor Ligthert" <no**********@planet.nl> wrote in message news:e%****************@TK2MSFTNGP11.phx.gbl... Hi Jay B. (And Bill)
I never come with documents, however this greath Dutchman will turn
around about your writting.
(He has done very much for modern programming, in my idea most modern languages derives partialy from his ideas)
http://www.cs.utexas.edu/users/EWD/
http://www.acm.org/classics/oct95/
Cor
Hi Jay, First a question: Why are you attempting to build a long thread? ;-)
Because I always know this hits me, I have seen so often bad programs which
with thinking how to provide the "goto" became suddenly much better (not a
religion, a trick to make better programs).
Remember bad use of a Goto does not make the Goto bad!
The Goto has after somewhere 1970 always been for me a bad command (In the
begin it was nothing more than a branch unconditional)
Too many developers think Goto is Bad! as they have seen bad uses of Goto too often...
In my idea still Goto's in scripting languages, it is for not good
programmers more easy to understand I think.
The second link is interesting, I don't see what you are trying to say
with the first (other then who wrote the second).
The first was to show who wrote it, not a simple Dutchman, which you may
think when you see the second link.
:-)
Cor
* "Cor Ligthert" <no**********@planet.nl> scripsit: I never come with documents, however this greath Dutchman will turn around about your writting.
(He has done very much for modern programming, in my idea most modern languages derives partialy from his ideas)
Dijkstra formulared the "Dining Philosophers' Problem", didn't he ;-).
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Herfried, Dijkstra formulared the "Dining Philosophers' Problem", didn't he ;-).
I like the "Dining Philosophers' Problem", I have a VB.NET implementation I
wrote someplace...
I believe you are correct, I don't have my reference handy...
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de... * "Cor Ligthert" <no**********@planet.nl> scripsit: I never come with documents, however this greath Dutchman will turn
around about your writting.
(He has done very much for modern programming, in my idea most modern languages derives partialy from his ideas)
Dijkstra formulared the "Dining Philosophers' Problem", didn't he ;-).
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hayri ERDENER |
last post by:
hi,
what is the equivalent of C languages' goto statement in python?
best regards
|
by: Grasshopper |
last post by:
Hi,
I am automating Access reports to PDF using PDF Writer 6.0. I've
created a DTS package to run the reports and schedule a job to run this
DTS package. If I PC Anywhere into the server on...
|
by: Ed Staffin |
last post by:
Hi,
In vb6, if I had an error handler I could catch an error,
make a correction and then try it again using resume. I
want to do the same thing in vb.net.
I am trying to deal with some...
|
by: eBob.com |
last post by:
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)
Here's my code ...
For Each Thing As OFI...
|
by: Goran Djuranovic |
last post by:
Hi All,
Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this:
<Root>
<Customer>
<Name>MyName</Name>
</Customer>...
|
by: marora |
last post by:
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
|
by: Rui Maciel |
last post by:
I've been delving into finite state machines and at this time it seems that
the best way to implement them is through an intense use of the goto
statement. Yet, everyone plus their granmother is...
|
by: O.B. |
last post by:
Does C# support anything like PHP's break command that optionally
accepts a parameter specifying how many loops to break out of?
|
by: Mientje |
last post by:
I've made an Access 2007 database to store information about the lessonplans I have to make every schoolyear.
I want to export the data form the table "Lesvoorbereiding" (Lessonplans in English) to...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |