Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 01:00 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBASIC: Editor or Terminal?!

     Page 3 of 3    
Author Message
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 05:16pm 17 Aug 2019
Copy link to clipboard 
Print this post

  lizby said  
  Poppy said  Here we could come back to Classic BASIC for all first steppers!


Line numbers and only GOTO for program control? We might as well teach typing by having learners carve letters in wood blocks and set them up in presses.

(I realize you were joking (at least partly)).


You won't get very far in ASM without jmp and you are totally respected as a programmer for writing code at such a low level.

Maybe we should have a jmp alias for GOTO and then we'd be regarded as programming gods  
 
ceptimus
Senior Member

Joined: 05/07/2019
Location: United Kingdom
Posts: 130
Posted: 05:50pm 17 Aug 2019
Copy link to clipboard 
Print this post

Go (Golang) which is a very modern clean language, still has a goto.  It's recommended not to use it very often, but as the authors of the language rightly say, there are some conditions where the standard flow control constructs don't do quite what you need, and you end up doing things that would be even uglier than goto.

An example is when a condition inside some deeply nested loop means that you want to exit the outer loop.  You would normally have to define some special 'finished' flag, then exit each loop and test the flag in all the outer loops to exit those too.
As well as goto, the Go language also lets you put a label on a loop, such as outer: or whatever you want to call it, and then you can do "break outer" even from a point that's say another four or five loops deeper (break is the equivalent of MMBASIC's Exit - the same as it is in C and other similar languages).

In Go and C, it's also legal to just return from a function from inside loops, so you can also do it by factoring out the nested loops to a separate function.

The MMBasic manual specifically warns about not doing EXIT SUB or EXIT FUNCTION from inside a FOR NEXT loop, so you can't do that and I guess it's not also not legal to use GOTO to jump out of a loop for the same reason (one for the gurus to confirm).  So I do resort to extra flags, setting the loop variables to the terminating values, and other tricks like that when I want to abort a nested loop early.
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 09:35pm 17 Aug 2019
Copy link to clipboard 
Print this post

  lizby said  Line numbers and only GOTO for program control? We might as well teach typing by having learners carve letters in wood blocks and set them up in presses.
Hey .... that's what us geezers had to put up with in the 1950s. I've still got those wood blocks around here somewhere .....

Paul in NY
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 09:42pm 17 Aug 2019
Copy link to clipboard 
Print this post

  Tinine said  You won't get very far in ASM without jmp and you are totally respected as a programmer for writing code at such a low level.

Maybe we should have a jmp alias for GOTO and then we'd be regarded as programming gods  
Back in 1958 Professor Phillips gave me the task of resolving the far jumps for the IBM 1401 Cornell assembler. Nowadays the joke becomes how far can you jump in a 4K core with 32 bit word length.

Paul in NY
 
BrianP
Senior Member

Joined: 30/03/2017
Location: Australia
Posts: 292
Posted: 04:11am 18 Aug 2019
Copy link to clipboard 
Print this post

Poppy said:
GOTO is generally useful, if the usage well-thought and line numbers for beginners can be useful for proactive structuring.

I agree with this - for the very newbie to programming it gives a focus point for structure.
Then easy to move on to labels...

B
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 09:23am 18 Aug 2019
Copy link to clipboard 
Print this post

  BrianP said  Poppy said:
GOTO is generally useful, if the usage well-thought and line numbers for beginners can be useful for proactive structuring.

I agree with this - for the very newbie to programming it gives a focus point for structure.
Then easy to move on to labels...

B


This is exactly what I mean!


Andre ... such a GURU?
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 2989
Posted: 11:54am 18 Aug 2019
Copy link to clipboard 
Print this post

I well understand the use of GOTO for jumping out of a deep structure when you encounter something you can't easily deal with there (and that EXIT FOR and EXIT SUB are just GOTOs with a different name), but I would argue that it is bad form to teach beginners a command that for the rest of their careers (if they take up programming), they will be told to avoid or minimize (with good reason).

  BrianP said  GOTO is generally useful, if the usage well-thought


That's the problem for beginners--getting to "well-thought usage". Might as well start with what is considered the "well-thought usage" of structured and modular code--not least because DO ... LOOP is not that much harder to grasp than MAIN: ... GOTO MAIN.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 01:10pm 18 Aug 2019
Copy link to clipboard 
Print this post

Actually vice versa I see no difference between a Do-Loop and a GOTO-LABEL:

Imagine You are at the LOOP-Line and You know you have to find the corresponding DO-Line, it is not more difficult to find the corresponding LABEL to a GOTO-Line.

In times of line numbering this all was confusing, but with LABELs it isnīt any more, everything else is just a matter of individual taste as BASIC never will be more than a language for hobbyists being only responsible for themselves.

But a technical reason can just be auto-structuring and syntax-highlighting within defined LOOPs by an editor/IDE, lacking within unrecognized GOTO-Blocks.

I think it is almost more important to cherish the value of REMarks!

But if a beginner does not reach any state of more sophisticated methodicalness then he is just not the one to become any kind of real programmer at all, so BASIC is just a symptom and not the cause.

Of cause you are completely right that in the first instance it is all a matter of teaching correctly how to use a tool reasonably, but simply condemning GOTO like many others do cannot be the right way.

Sometimes I use GOTO myself just to break out and this can help me to find out something special if necessary while coding. It is just a tool ... but I would miss it therefore.


Andre ... such a GURU?
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024