Goto, Break and Continue
category: offtopic [glöplog]
“GOTO Considered Harmful” Considered Harmful (1987)
More seriously, I think porocyon is on the right track. The goto statement in modern languages is pretty harmless when compared to insane stuff they did with e.g. FORTRAN. Also, since this is about C#, the unpredictable control flow across function boundaries caused by exception handling seems much more like a problem. At least in C++ you've got RAII.
More seriously, I think porocyon is on the right track. The goto statement in modern languages is pretty harmless when compared to insane stuff they did with e.g. FORTRAN. Also, since this is about C#, the unpredictable control flow across function boundaries caused by exception handling seems much more like a problem. At least in C++ you've got RAII.
There truly is a place for everything. I can't remember ever using goto in C, though, but I have been in a situation where longjmp was the only sensible solution.
Now, let’s talk about exceptions. They’re a celebrated feature that basically says ”goto somewhere;”
I take exception to exceptions being “celebrated”.
Exceptions are essentially COME FROM programming. INTERCAL is the only language honest about this, of course.
Exceptions are essentially COME FROM programming. INTERCAL is the only language honest about this, of course.
Another cool use of Goto is having fun when you know someone will read it... A friend of mine (ArmOric) wrote the following for a C programmer:
Code:
10 GOTO 20
20 REM It scared you, didn't it?
30...
goto make_a_demo_about_it
my code wouldn't work without goto #asm ;)
Ah, I remember GOTO - When programming my Atari 8-Bit in BASIC, I would usually use that, although GOSUB was available, I don't think I ever used it. I carried on that way for years, until AMOS on the Amiga, where my game Brainbow was the last time I used the GOTO statement. For my subsequent software titles, I discovered the joys of Procedures and Functions, and I felt liberated and more efficient with my coding.
you can try to code as good as possible without gotos and breaks'n'stuff but at the end your compiler will laugh at you and replace all your nifty high level stuff by millions of gotos and breaks :) .. (I know, there are some clever branchless optimization technics in modern compilers and ARM has nice conditional instructions ...)
there are like 100000 stackoverflow discussions about this
goto one of those? :)
goto one of those? :)
@maali, better not, the ppl over there are not trueskool enough.
better stick to python anyway, not only it makes you do everything that c/c++ people forbade, it looks less nerdy on your CV
pff, ruby all the way. or qruby. quick-ruby. quick. q.
Quote:
done thatq.
Quote:
Q is no longer supported, see Pure instead
pure is purely uninteresting (at least that's my verdict after 10mins of googling)
I wasn't implying anything ^^
But it was fun doing dsp with equations in Q while it was an university course.
But it was fun doing dsp with equations in Q while it was an university course.
Gridfighter 3D is full of GOTOs. They break out of loops, they set variables based on other conditions of variables, they jump out of subs back into the main program, there's even one for going back to the splash screen after entering a high score. It's also written in BASIC, so there's that.
I have nothing further to contribute to this discussion. :P
I have nothing further to contribute to this discussion. :P
I forgot the CONTINUE bit, never really understood it's relevance in ZX BASIC.
Anyway, is this a demo?
Anyway, is this a demo?
I'm actually surprised you guys fell for such a basic / beaten up to death discussion... but whatever...
Preacher wrote:
There are of course few existing concepts for handling break and continue inside nested loops, like labelled break/continue in Java.
Occasionally some people bring up the old idea of break with a parameter e.g. break(2), break(3), etc... but it was discussed many times why it's a bad idea and why labelled break is better.
And as Preacher says in C++ you only have goto for that (read also in Notes for break at cppreference.com).
I can also imagine a realistic use-case: let say you have algorithm with nice asymptotically optimal complexity, but you still want to optimize the shit out of it for small input size with say cubic or quadratic complexity (to save literally just a few CPU cycles). However, if you feel like you have to use it too often, you are probably using it wrong ;)
Preacher wrote:
Quote:
Breaking out of a nested loop is also a valid use case for goto.
There are of course few existing concepts for handling break and continue inside nested loops, like labelled break/continue in Java.
Occasionally some people bring up the old idea of break with a parameter e.g. break(2), break(3), etc... but it was discussed many times why it's a bad idea and why labelled break is better.
And as Preacher says in C++ you only have goto for that (read also in Notes for break at cppreference.com).
I can also imagine a realistic use-case: let say you have algorithm with nice asymptotically optimal complexity, but you still want to optimize the shit out of it for small input size with say cubic or quadratic complexity (to save literally just a few CPU cycles). However, if you feel like you have to use it too often, you are probably using it wrong ;)
ain't nobody have time to read this thread
don't waste your time pondering about philosophical do's and don'ts.
the primary goal is to write simple, understandable, maintainable, non-bloated code. if gotos et al help to reach that goal - use them. evaluate on a per use-case basis.
the same holds true for usage of design patterns etc.
and now concentrate on getting shit done (read: write a demo about it)!
the primary goal is to write simple, understandable, maintainable, non-bloated code. if gotos et al help to reach that goal - use them. evaluate on a per use-case basis.
the same holds true for usage of design patterns etc.
and now concentrate on getting shit done (read: write a demo about it)!
The problem with goto is that it's heavily stigmatised, while other bad programming practices are considered ok. So you may write clear and maintainable code using a goto somewhere where it's objectively beneficial, and that other bloke writes awful spaghetti but no single goto in it. Guess who's going to get scolded on a code review.