Lars Fosdal 1732 Posted March 21 Fun observations on the GoTo topic: https://jerf.org/iri/post/2024/goto/ 4 1 Share this post Link to post
Anders Melander 1639 Posted March 21 1 hour ago, Lars Fosdal said: Fun observations on the GoTo topic: https://jerf.org/iri/post/2024/goto/ Quote When I see modern code that uses goto, I actually find that to be a marker that it was probably written by highly skilled programmers. True, but don't say that out loud. sEE, i'M uSiNg GoToS; iM A hiGhLy SkIlLeD pRoGraMmEr! 1 Share this post Link to post
Pat Foley 50 Posted March 21 Here is a dangerous example of Goto causing endless loop you never finish this gamebook's first edition. In the gamebook You Can Be The Stainless Steel Rat by Harrison. There's an example of a typo goto 290 should be goto 190. https://stainlesssteelrat.fandom.com/wiki/You_Can_Be_The_Stainless_Steel_Rat 2 Share this post Link to post
Brandon Staggs 185 Posted March 21 Quote DELETE FROM shibboleths WHERE value LIKE "%goto%". Dumping on modern goto is not smart and wise and a sign of a good programmer, it’s a sign you don’t understand why goto is… or rather, was… bad. That's great! Share this post Link to post
A.M. Hoornweg 138 Posted March 25 On 11/4/2022 at 7:08 PM, dummzeuch said: I actually used a goto for debugging today. The reason was that at the end of a function I check the result and for a particular result I want to repeat the code in the function in order to step through it: function whatever: SomeType; label RepeatMe; begin RepeatMe: // some code that generates the result if Result = ResultIWantToDebug then goto RepeatMe; // <== put a breakpoint here // some more code end; No need for this, the debugger has that functionality built-in: -Set a breakpoint on your corner case condition and wait until it fires -Right-click the line where you want to "go to" -Enter submenu "Debug" -Select menu item "Set next statement". The debugger will jump here when you single-step through your code. Share this post Link to post
pmcgee 10 Posted Wednesday at 04:47 PM (edited) Something I posted on the ADUG forum ... this C code (when I saw it) was posted on twitter as an amusing post about C. [ Cursed C code ] But after I'd thought about it for a bit, it occurred to me that maybe I could do the same in Delphi. And we can. 🙂 {$APPTYPE CONSOLE} program Project1; type range_struct = record type Tstate = (at_start, in_loop, done); var stop, step, i, start : integer; state : Tstate; function resume() : integer; constructor λ ( _start, _stop : integer; _step : integer = 1); end; constructor range_struct.λ( _start, _stop, _step:integer); begin start := _start; stop := _stop; step := _step; state := at_start; end; function range_struct.resume() : integer; label α,β,δ; begin case state of at_start : goto α; in_loop : goto β; done : goto δ; end; α : i:=start; repeat begin state := in_loop; exit(i); β : i := i + step; end until i >= stop; state := done; δ : exit(0); end; begin var ρ := range_struct.λ(1,20,2); var π := range_struct.λ(2,20,2); for var i in [1..5] do begin writeln('a ',i:2, 'th call : ', ρ.resume); writeln(' b ',i:2, 'th call : ', π.resume); end; writeln; writeln('Mwah ha ha. GOTO is back, baby!'); readln; end. That wasn't the original function-calling code that I had posted. It was only after a bit of mental digestion that I realised that this is (in my opinion) a really good, simplified, understandable model of a coroutine. ... and soon after I found out the original C code was part of an article commenting on c++ coroutines : https://probablydance.com/2021/10/31/c-coroutines-do-not-spark-joy/ Edited Wednesday at 04:57 PM by pmcgee Share this post Link to post
Die Holländer 20 Posted Thursday at 06:38 AM In the early BASIC times, like for the ❤️ ZX-Spectrum ❤️ there were no functions or procedures but instead they introducted a way to jump to another part of the source and return to the next line after the jump. The statements: Gosub and Return. 10 LET A=0 20 PRINT "ENTER A NUMBER: " 30 INPUT N 40 GOSUB 100 50 PRINT "THE RESULT IS ";A 60 END 100 A = N * 2 110 RETURN Share this post Link to post
Sherlock 632 Posted Thursday at 08:44 AM That reminds me: Quote BASIC programmers never die, they GOSUB and never RETURN. 4 Share this post Link to post
Cristian Peța 94 Posted Friday at 11:04 AM On 4/25/2024 at 9:38 AM, Die Holländer said: In the early BASIC times, like for the ❤️ ZX-Spectrum ❤️ there were no functions or procedures but instead they introducted a way to jump to another part of the source and return to the next line after the jump. The statements: Gosub and Return. ZX-Spectrum BASIC was like an easier assembler where you use CALL and RET (Z80 assembler). Share this post Link to post
Bill Meyer 333 Posted 14 hours ago There is a classic, if dusty, article from Donald Knuth: https://pic.plover.com/knuth-GOTO.pdf Share this post Link to post
David Heffernan 2300 Posted 4 hours ago On 4/26/2024 at 12:04 PM, Cristian Peța said: ZX-Spectrum BASIC was like an easier assembler where you use CALL and RET (Z80 assembler). Speccie basic was a terrible language. The beeb had a much better variant. Share this post Link to post