pouët.net

Go to bottom

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.
added on the 2018-09-25 20:48:12 by cce cce
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.
added on the 2018-09-25 21:04:56 by sol_hsa sol_hsa
Now, let’s talk about exceptions. They’re a celebrated feature that basically says ”goto somewhere;”
added on the 2018-09-25 21:08:39 by Preacher Preacher
I take exception to exceptions being “celebrated”.

Exceptions are essentially COME FROM programming. INTERCAL is the only language honest about this, of course.
added on the 2018-09-25 21:29:46 by Sesse Sesse
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...
added on the 2018-09-25 21:50:56 by baah baah
goto make_a_demo_about_it
added on the 2018-09-26 01:04:59 by T$ T$
my code wouldn't work without goto #asm ;)
added on the 2018-09-26 19:22:40 by Asato Asato
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.
added on the 2018-09-26 21:02:36 by Foebane72 Foebane72
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 ...)
added on the 2018-09-26 22:42:22 by Asato Asato
there are like 100000 stackoverflow discussions about this
goto one of those? :)
added on the 2018-09-27 00:40:58 by maali maali
@maali, better not, the ppl over there are not trueskool enough.
added on the 2018-09-27 00:43:52 by jco jco
better stick to python anyway, not only it makes you do everything that c/c++ people forbade, it looks less nerdy on your CV
added on the 2018-09-27 01:04:11 by maali maali
pff, ruby all the way. or qruby. quick-ruby. quick. q.
added on the 2018-09-27 01:10:48 by jco jco
Quote:
q.
done that
added on the 2018-09-27 01:15:43 by xTr1m xTr1m
Quote:
Q is no longer supported, see Pure instead
added on the 2018-09-27 01:19:55 by jco jco
pure is purely uninteresting (at least that's my verdict after 10mins of googling)
added on the 2018-09-27 01:25:39 by jco jco
I wasn't implying anything ^^
But it was fun doing dsp with equations in Q while it was an university course.
added on the 2018-09-27 11:01:39 by xTr1m xTr1m
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
added on the 2018-09-28 02:18:34 by jmph jmph
I forgot the CONTINUE bit, never really understood it's relevance in ZX BASIC.
Anyway, is this a demo?
added on the 2018-09-28 17:41:10 by FunGas FunGas
I'm actually surprised you guys fell for such a basic / beaten up to death discussion... but whatever...

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 ;)
added on the 2018-09-28 23:06:10 by tomkh tomkh
ain't nobody have time to read this thread
added on the 2018-09-29 05:21:00 by sigflup sigflup
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)!
added on the 2018-09-29 12:23:22 by arm1n arm1n
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.
added on the 2018-09-30 09:41:29 by svo svo

login

Go to top