Click here to Skip to main content
15,913,685 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: goto statement Pin
_Maxxx_10-Nov-13 14:35
professional_Maxxx_10-Nov-13 14:35 
GeneralRe: goto statement Pin
Tarek Elqusi10-Nov-13 18:46
professionalTarek Elqusi10-Nov-13 18:46 
GeneralRe: goto statement Pin
Mark_Wallace10-Nov-13 20:47
Mark_Wallace10-Nov-13 20:47 
GeneralRe: goto statement Pin
Mark H210-Nov-13 21:56
Mark H210-Nov-13 21:56 
GeneralRe: goto statement Pin
Stefan_Lang10-Nov-13 23:24
Stefan_Lang10-Nov-13 23:24 
GeneralRe: goto statement Pin
vl211-Nov-13 7:49
vl211-Nov-13 7:49 
GeneralRe: goto statement Pin
jaybus5610-Nov-13 22:11
jaybus5610-Nov-13 22:11 
GeneralRe: goto statement Pin
Stefan_Lang10-Nov-13 23:13
Stefan_Lang10-Nov-13 23:13 
1. If it is critical that your code is correct, don't use goto: it has the capability to jump out of or into one or more nesting layers - even backwards - and thus makes it considerably harder to verify the correctness of the code.

2. If there is more than one programmer on the team, don't use goto: using it makes it considerably harder for another programmer to understand the flow of code, and what it is supposed to do.

3. If you intend to build on and maintain the code over a period of more than a couple of months, don't use goto: viewing a piece of code that you yourself wrote a couple of months ago is often not so much different from viewing another programmers' code - see item 2 above.

Please note that modern programming languages have plenty of alternatives that can be used in many cases where goto could be used. In C/C++, here are some examples:
- to repeat a block of code, use a for, while, or do loop construct rather than jumping backwards
- to skip over some piece of code, use an if-block rather than jumping forward
- to skip over the rest of a loop body, use continue
- to exit out of a loop, use break
In C++ you should also use the standard exception handling mechanism rather than using goto as an error exit mechanism. (There is no equivalent in C, so you might argue that in C the use of goto for that purpose is acceptable - but see below!)

The main reason however that you shouldn't use goto is that there is no benefit. Over the past 30 years I've used, learned about, read about, and had plenty of discussions about goto. In all that time I've never heard or read one compelling argument in favor of using it. Yes, you can use it to reduce or avoid nesting, or otherwise reduce the amount of code. But that by itself is not a valid argument in my book.
GeneralRe: goto statement Pin
vl211-Nov-13 7:46
vl211-Nov-13 7:46 
GeneralRe: goto statement Pin
Stefan_Lang11-Nov-13 20:30
Stefan_Lang11-Nov-13 20:30 
GeneralRe: goto statement Pin
vl212-Nov-13 0:44
vl212-Nov-13 0:44 
GeneralRe: goto statement Pin
jschell12-Nov-13 9:56
jschell12-Nov-13 9:56 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 21:19
Stefan_Lang12-Nov-13 21:19 
GeneralRe: goto statement Pin
jschell13-Nov-13 10:27
jschell13-Nov-13 10:27 
GeneralRe: goto statement Pin
Stefan_Lang13-Nov-13 21:07
Stefan_Lang13-Nov-13 21:07 
GeneralRe: goto statement Pin
jschell14-Nov-13 7:54
jschell14-Nov-13 7:54 
GeneralRe: goto statement Pin
Stefan_Lang14-Nov-13 23:15
Stefan_Lang14-Nov-13 23:15 
GeneralRe: goto statement Pin
jschell15-Nov-13 12:28
jschell15-Nov-13 12:28 
GeneralRe: goto statement Pin
Stefan_Lang17-Nov-13 21:29
Stefan_Lang17-Nov-13 21:29 
GeneralRe: goto statement Pin
jschell18-Nov-13 8:13
jschell18-Nov-13 8:13 
GeneralRe: goto statement Pin
Stefan_Lang13-Nov-13 21:22
Stefan_Lang13-Nov-13 21:22 
GeneralRe: goto statement Pin
jschell18-Nov-13 8:17
jschell18-Nov-13 8:17 
GeneralRe: goto statement Pin
Stefan_Lang18-Nov-13 20:54
Stefan_Lang18-Nov-13 20:54 
GeneralRe: goto statement Pin
jschell19-Nov-13 10:39
jschell19-Nov-13 10:39 
GeneralRe: goto statement Pin
Stefan_Lang19-Nov-13 22:33
Stefan_Lang19-Nov-13 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.