Lars Fosdal 1800 Posted March 21, 2024 Fun observations on the GoTo topic: https://jerf.org/iri/post/2024/goto/ 4 1 Share this post Link to post
Anders Melander 1852 Posted March 21, 2024 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 52 Posted March 21, 2024 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 324 Posted March 21, 2024 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 147 Posted March 25, 2024 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 23 Posted April 24, 2024 (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 April 24, 2024 by pmcgee Share this post Link to post
Die Holländer 56 Posted April 25, 2024 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 668 Posted April 25, 2024 That reminds me: Quote BASIC programmers never die, they GOSUB and never RETURN. 6 Share this post Link to post
Cristian Peța 108 Posted April 26, 2024 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 338 Posted April 27, 2024 There is a classic, if dusty, article from Donald Knuth: https://pic.plover.com/knuth-GOTO.pdf 1 1 Share this post Link to post
David Heffernan 2366 Posted April 28, 2024 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
Die Holländer 56 Posted April 29, 2024 On 4/28/2024 at 8:17 AM, David Heffernan said: Speccie basic was a terrible language. The beeb had a much better variant. Ahh, a typical reaction that started in that time.. My Commodore 64 is much better. My Apple is much better than your Windows My Iphone is much better than you Android phone. My Javascript language is much better than ... 1 Share this post Link to post
David Heffernan 2366 Posted April 29, 2024 1 hour ago, Die Holländer said: Ahh, a typical reaction that started in that time.. My Commodore 64 is much better. My Apple is much better than your Windows My Iphone is much better than you Android phone. My Javascript language is much better than ... Well, the Speccie and the 64 did have better games. The 64 had epic sound. The beeb was more used for hobbyist coding then the other computers of that age. And the beeb did have by far the best programming language of these. There were real differences. Share this post Link to post
Lars Fosdal 1800 Posted April 29, 2024 I still have a Memotech MTX512 in storage 🙂 Share this post Link to post
Leif Uneus 43 Posted April 29, 2024 Ahh, the horror of programming games with the Commodore VIC-20 using the tape recorder ... Share this post Link to post