News:

;) This forum is the property of Proton software developers

Main Menu

Importance of jumping

Started by shantanu@india, Aug 18, 2021, 07:03 AM

Previous topic - Next topic

shantanu@india

Hi,
The title is deliberately misleading.....jumping means 'GoTo' in Basic or 'JMP' in assembler...whatever... :)
I have jumped from here & there right from the day one when I started coding in 1987.
But GoTo/Labels/Jumps are not allowed in Python since it is a highly structured language!!
I nowadays use micropython to write code for ESP8266 & find the absence of jump a definite impediment.
Maybe the key lies in the mode of working of an interpreted language like python....jumping prevents linear & sequential code execution by the virtual machine.
Regards
Shantanu

John Drew

Hi Shantanu,
I agree, jumps can be very helpful used in the right spot.
However I'm not so sure about the reference to being highly structured leading to no jumps. Pascal is highly structured yet has labels and goto etc.
I suspect your second suggestion is more likely.
Best wishes
John

shantanu@india

Yes John I am learning to live without jumping.
In some deeply introspective moments I have started to feel that GoTo is really an escape route for average coders... but unfortunately I am still average. ;D
Regards
Shantanu

Stephen Moss

It really depends on how you are using the GoTo commands, which in part is determined by how you structure you program/coding style.
I think in the beginning that many of us older programmers used GoTo statements a lot due to how coding was generally structured back in the day and that coding back then was more a work of self discovery and GoTo is easy to understand, as opposed to these days where many are taught programming in the modern Object Oriented style at school to some extent.

These days I think GoTo is generally not required as (particularly if you are used to a language like Visual Basic) you become familiar with braking the code down into many subroutines rather then jumping back and fourth through one long listing. So instead of using GoTo I now tend to create a Subroutine and call that instead as breaking the code down into small subroutine can make it easier to navigate and manage as I now try to keep the code for a subroutine to one screen as it is easy to see what is going on with the code and spot mistakes in that particular function rather than scrolling through several screens of code of a larger listing to find it.

The only times I tend to use GoTo these days is if I have a condition that requires skipping a section of code within a subroutine and even then I generally only do that to help with debugging to either decrease the time the program takes to reach a particular section during testing or to skip parts of the subroutine to help identify which area of it is causing the problem.

top204

#4
The Goto command is actually very important with all languages. It is just the nerds who created the "dreadful" Python syntax that thought they knew better than all others. :-)

The goto command is even supported in C++, which is the utmost in object orientated and event driven languages.

Within a microcontroller environment, the Goto command is even more important, because it can skip a whole sequence of If or ElseIf commands, and make code operate faster, and a Goto command within a procedure is extremely handy. So with an interpreted language such as Python, it is very much an important command, although these days, code efficiency does not seem too important, just get a faster device and write sloppy code, as is done on PCs. :-) That statement is obviously true now because of the plethora of "interpreted" slow languages available and popular. It reminds me of the 1980s so much, with the interpreted BASIC languages that were available then and they were massively popular. But eventually the interpreted languages died out because machines were not reaching the speeds required for more dedicated programs. The same will happen with the current intrepreted languages, and they will become true compiled languages, and not "byte code" interpreted types with the false term "compiled" alongside them. So much for "learn from history". :-)

I even use the goto command within my C++ programs, to skip huge sections of comparisons and jump to the end section of a function if what is needed has been found early in the code sequence.

John Drew

G'day all,
On one of my early programs with a 16F628A I had to resort to Goto because I'd gone too deep in subroutines and ran out of stack space.
When starting out I only had goto in Microbee BASIC and my programs were classic string code with jumps to and fro all over the place. A nightmare to follow.

All that aside Goto has its place as per Les's examples.

Turbo Pascal taught me about structure and how to write easier to follow programs.

There are many similarities between non Windows pre-object Pascal and well written Positron code.
John

top204

Many thanks John.

The original Pascal syntax was nice to use, but I never liked all of those "begin" and "end" directives all over the place, or "end" not placed in some comparison sequences, but it is something a person gets used too, and I write in Delphi a lot. :-)



keytapper

I use goto in particular to jump to another subroutine, rather than using Return twice. There's some drawback when it comes to jump from a subroutine/procedure to another, the code needs EndSub or EndProc in the origin, in all of the cases. For some special case every code word count, specially when the program memory is closed to be filled.
Ignorance comes with a cost