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 KingdomPosts: 1646 |
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 KingdomPosts: 130 |
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 StatesPosts: 769 |
Paul in NY |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
Maybe we should have a jmp alias for GOTO and then we'd be regarded as programming gods Paul in NY |
||||
BrianP Senior Member Joined: 30/03/2017 Location: AustraliaPosts: 292 |
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: GermanyPosts: 486 |
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 StatesPosts: 2989 |
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). 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: GermanyPosts: 486 |
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 |