Click here to Skip to main content
15,902,299 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
Bill_Hallahan13-Nov-13 17:23
Bill_Hallahan13-Nov-13 17:23 
GeneralRe: goto statement Pin
jschell14-Nov-13 7:50
jschell14-Nov-13 7:50 
GeneralRe: goto statement Pin
Bill_Hallahan14-Nov-13 14:02
Bill_Hallahan14-Nov-13 14:02 
GeneralRe: goto statement Pin
jschell12-Nov-13 9:46
jschell12-Nov-13 9:46 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 13:25
Bill_Hallahan12-Nov-13 13:25 
GeneralRe: goto statement Pin
jschell13-Nov-13 9:49
jschell13-Nov-13 9:49 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 20:50
Stefan_Lang12-Nov-13 20:50 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 12:32
Bill_Hallahan12-Nov-13 12:32 
We essentially agree that gotos are undesirable the vast majority of the time.

I'm just not positive that gotos are bad all of the time. One can develop tunnel realities, even with decades of experience.

Take the saying at the end of your post: "GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)"

While I expect that is often the case, I would think it untrue in some situations. If a well-managed team were to find a reason to use a goto, and the team had guidelines that were documented in the code around the goto to not do this elsewhere, then I don't think that goto's would necessarily proliferate.

But again, I've always used break or continue and avoided them too, and I agree with your philosophies, just not the absolutist part of your philosophy.

I don't know absolutely every situation for ever program in every context, and there actually is a documented benefit to gotos in some circumstances. Even though there can be dire consequences from using a single goto, nonetheless the tradeoff might be that without using a goto, something isn't fast enough to do that job. In that case, the developer might decide that practicality takes precedence over good software engineering. I can't prove that situation doesn't exist. So I can't be absolute about the rule.

I don't get that someone posted that goto's were needed for a state machine. A switch statement works, and there are other solutions too. The book "Design Patterns" provides the Strategy pattern, which (and I expect you know this already Stefan) where different "state" classes derive from a common base class, and switching states is done by switching the type of object. Virtual methods are called on the current state object.

And, except in rare instances, I suspect a goto isn't much faster than well-written code, and probably even slower in some cases. Today, often instruction cache fetch limitations, data cache fetch limitations, or instruction ordering (the last less of an issue with modern Intel compilers than it used to be) affect performance more than the number of instructions in the code path. (I know you know this too). So, in general, the only way today to find out if code is faster is to profile the code. (Note, I wrote "in general" there - of course there are exceptions). I would need pretty strong proof in a particular situation to even consider that using a goto is justified.

Perhaps no such situation exists. I can't prove that though.
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 21:34
Stefan_Lang12-Nov-13 21:34 
GeneralRe: goto statement Pin
Bill_Hallahan13-Nov-13 7:16
Bill_Hallahan13-Nov-13 7:16 
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 
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 

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.