Jump to content

Recommended Posts

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!

 

  • Haha 1

Share this post


Link to post
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
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

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 by pmcgee

Share this post


Link to post

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

That reminds me:

Quote

BASIC programmers never die, they GOSUB and never RETURN.

 

  • Haha 4

Share this post


Link to post
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×