GOTO one day in B4A (as in B4ppc)?

DOM85

Active Member
Licensed User
Longtime User
Even if the use of loops is often better, some kinds of app would be simplified with "GOTO" rather loops when control is given to many parts of the program on external events.
No chance to see it in B4a in the future? (as in B4ppc, in machine code (jumps), etc )
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Even if the use of loops is often better, some kinds of app would be simplified with "GOTO" rather loops when control is given to many parts of the program on external events.
No chance to see it in B4a in the future? (as in B4ppc, in machine code (jumps), etc )

If you haven't already searched the forums for "goto", you may want to try it. This subject has been beaten to death on here. As a side note, there is a WishList forum for posting feature wishes for B4A.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Even if the use of loops is often better, some kinds of app would be simplified with "GOTO" rather loops when control is given to many parts of the program on external events.
No chance to see it in B4a in the future? (as in B4ppc, in machine code (jumps), etc )

GOTO encourages messy/spaghetti code.
If you properly modularize your code, you don't even need it.
 
Upvote 0

DOM85

Active Member
Licensed User
Longtime User
GOTO encourages messy/spaghetti code.
If you properly modularize your code, you don't even need it.

Thank you for your "advice"!!!
I am not so fundamentalist against goto(s). It is not possible to make all diys with only a knife or a screwdriver? Sometimes (maybe rare) goto are more efficient. Imagine how could works an OS without jumps and conditional jumps (goto equivalents)?

But maybe i would have put this thread in Whishes, sorry.
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
In defense of GoTo

Please check out Goto - encyclopedia article about Goto. for a concise explanation of what happened to "GoTo".

I have been programming since about 1967 and actually lived through the development of 'Structured Programming' and the its eventual evolution into 'Object Oriented Programming. With regard to 'GoTo', the discussion has been going on since 1959, probably because of the large quantity of 'spaghetti code' that was being produced. It is still possible to produce 'spaghetti code' even using structured or object oriented programming - I have seen quite a bit of it. It usually results from a program that was written 'ad hoc' with no real advance thought or planning of how it should be structured.

However, the real argument about 'GoTo' was that the its use should be very restricted. Unfortunately, this was taken by many to mean that 'GoTo' should not be allowed at all. But, in actual fact, VERY selective use of 'GoTo' can significantly reduce program size and/or greatly speed up execution. I remember being asked to streamline a 400 page program (26,000 lines) that ran way too slow to be usable. My re-edited version, with about 15 'GoTos' in very selected locations came out at 300 pages (19,500 lines) and ran at a more reasonable speed. My own opinion is that 'GoTo' is fine, provided that one limits it use as much as possible, and the source code contains good explanatory comments as to why it appears at any particular location (Good code should be well commented anyway so a different programmer can follow the logic - or the creator can follow it when he/she comes back to it a year or two later).

Having said that, since our B4A source ends up being turned into Java code, a language that does not include 'GoTo', I expect it would be nearly impossible to add a 'GoTo' to it.

But there are ways around the missing 'GoTo'. Bear in mind that things like 'For...Next' loops, 'While...Loop' and 'Select value' with 'Case' elements are actually hidden forms of 'GoTo' and, with a little planning, a program can be structured to make use of these as a substitute for the missing 'GoTo'.

For a process that must be repeated over and over, but may have to branch to specific sections, the use of 'While condition...Loop containing a 'Select value' with a series of 'Case' items can accomplish almost the same effect as using 'GoTo'. The program will loop within the 'While', and can be made to exit the loop my altering the condition. By controlling and setting the 'value' used by the 'Select', the internal flow can be controlled very easily. Each 'Case' can contain calls to subroutines structured so that any particular case executes only those subroutines required to satisfy the particular need at that stage. For event driven elements, a call to a subroutine can be made in which the 'While' is left out, and the actual event can set whatever 'value' is needed to handle that particular event and take the program to the appropriate case. All that is needed is a bit of advance planning (learning to do flowcharts is a fast way to do this although I sometimes think the creation of flowcharts is something of a lost art).
 
Upvote 0
Top