Do you use the goto command?

Permabanned
Joined
15 Nov 2006
Posts
164
Location
Visit Athens
Do you use the goto statement?

OK the Fortran programmers of course yes! :D
But the others (C, Basic) etc....
IMHO it is useful sometimes. Anyway what's your opinion?
 
Last edited:
I don't think I've used it since the 80's

If you need it, you're inevitably missing out on a lot of things modern languages can do for you as you are still thinking in the old linear program fashion.
 
I use goto (C/C++) where it can improve either the clarity or the performance of the code, whichever is more important at the time. To the people who have blindly taken Dijkstra's blessings to heart, I suggest that you become familiar with the other side of the argument - ie, Donald Knuth's paper - "Structured Programming with go to Statements", for examples where goto's are better in many ways than traditional inflexible structured programming practices.
 
MrSeanKon said:
OK the Fortran programmers of course yes! :D
But the others (C, Basic) etc....
IMHO it is useful sometimes. Anyway what's your opinion?

Occasionally, as a last resort.

But never as a first option.
 
matja said:
I use goto (C/C++) where it can improve either the clarity or the performance of the code, whichever is more important at the time. To the people who have blindly taken Dijkstra's blessings to heart, I suggest that you become familiar with the other side of the argument - ie, Donald Knuth's paper - "Structured Programming with go to Statements", for examples where goto's are better in many ways than traditional inflexible structured programming practices.
I don't see how a JMP (a.k.a. "goto") instruction can ever improve performance as the processor can never predict it... :)
 
Visage said:
What about exiting from deep loops quickly?
Use the "break" statement :p To exit from nested loops use a boolean flag and conditionals on the loop conditions.
 
Last edited:
NathanE said:
... To exit from nested loops use a boolean flag and conditionals on the loop conditions.

or faster, a goto...

NathanE said:
I don't see how a JMP (a.k.a. "goto") instruction can ever improve performance as the processor can never predict it...

Actually, the branch target buffer logic in modern CPUs makes this case (static branch) the most optimal. On Intel Core 2, uop fusion makes static branches essentially free, unlike exiting from nested loops using various flags. But at the end of the day, whatever gets the job done in fewer bugs...
 
Last edited:
NathanE said:
Use the "break" statement :p To exit from nested loops use a boolean flag and conditionals on the loop conditions.

Some languages dont have break statements, and some dont have booleans. Some dont even have loops ;)
 
Visage said:
Some languages dont have break statements, and some dont have booleans. Some dont even have loops ;)
Yes and some languages don't have GOTO/JMP :p Java for instance :D

Catchy little sayings like that work both ways ya' know ;)
 
matja said:
or faster, a goto...



Actually, the branch target buffer logic in modern CPUs makes this case (static branch) the most optimal. On Intel Core 2, uop fusion makes static branches essentially free, unlike exiting from nested loops using various flags. But at the end of the day, whatever gets the job done in fewer bugs...
I'm not so sure about it being 'free'. But meh, it's all down to choice isn't it. I don't think either method is wrong and to be honest I might reconsider using GOTO in the nested loop scenario the next time it comes along.
 
NathanE said:
I'm not so sure about it being 'free'. But meh, it's all down to choice isn't it. I don't think either method is wrong and to be honest I might reconsider using GOTO in the nested loop scenario the next time it comes along.

Bust out vtune and check :p
 
NathanE said:
Yes and some languages don't have GOTO/JMP :p Java for instance :D

Incorrect - some VM implementations use goto/jumps.....the Java platform includes more than just the core language spec.

Catchy little sayings like that work both ways ya' know ;)

How very smug.
 
Visage said:
Incorrect
So you are saying that every language has GOTO? :D And it's one thing supporting it in the VM, but entirely another exposing it in the language itself...

How very smug.
Have to up the ante when you're about ;)
 
Last edited:
NathanE said:
So you are saying that every language has GOTO? :D

No. I've bnever said that. If I have then presumably you are able to point out where I did so.

And it's one thing supporting it in the VM, but entirely another exposing it in the language itself...

My original point was that GOTO's are sometimes necessary in languages that dont have some of the 'advanced' constructs that one commonly sees. It absence in a language such as Java is in no way indicative of its general utility.

Ada, for example, has been developed specifically for mission, safety and security critical software since the early 80's, and yet it has a GOTO statement......

Have to up the ante when you're about ;)

Being smug is fine, as long as one has something to be smug about.
 
Visage said:
No. I've bnever said that. If I have then presumably you are able to point out where I did so.
Erm when you said I was "incorrect" :confused:


My original point was that GOTO's are sometimes necessary in languages that dont have some of the 'advanced' constructs that one commonly sees. It absence in a language such as Java is in no way indicative of its general utility.
That's the first time you've made this point actually. It's a good point except that I doubt many people these days deal with languages which don't have high level constructs...

Ada, for example, has been developed specifically for mission, safety and security critical software since the early 80's, and yet it has a GOTO statement......
Ada? Did I read that right? Ada? :eek: Are you an academic or something? :D


Being smug is fine, as long as one has something to be smug about.
Whilst I like cheese, I'm not a mouse. You can't bait me that easily :D
 
Back
Top Bottom