From VB6 to Basic4android

Bill

Member
Licensed User
Longtime User
I can't believe that "goto" a simple time saving feature of basic, a language that you can sit and program a working example in minutes, is explicitly excommunicated!
The whole point of basic is ignored........... those who snobbishly dismiss the command evangelically spouting about Brian Kernighan and Dennis Ritchie (two guys who invented the biggest set back to computing in the 20th century inmho) are missing the point.
Frankly if I had known "goto" was missing I wouldn't have bought a copy of B4A....!!
 
Upvote 0

Bill

Member
Licensed User
Longtime User
Well it obviously wasn't my only criteria but just because something is possible you don't have to do it, I could cross the road hopping on one leg or dragging myself by the nose, would I feel good or virtuous about it? I've been programming in assembler for the best part of 40 years where would that be without an effective jump / branch or or two? Bah Humbug!
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
The missing "GOTO" that a lot of you are complaining about is missing for a reason.

Basic4android is converted to Java as part of the compilation process. While "Goto" is a reserved word in Java, the actual verb is not supported. THEREFORE, it would be extremely difficult (impossible??) to create a "Goto" in Basic4android. So lets leave it at that.

I miss "Goto" as well, but there are many ways to program your way around it - a couple have been mentioned such as "If...then...else.." as well as "Select...Case..." statements can function very well with a little creativity. Sometimes in converting old code (VB6 or old spaghetti BASIC of other versions), it can take a bit of thought but it can be done. For example, you can split a function into multiple parts, then use a Case statements to control which is called when, resulting in the same logic as the original program.
 
Upvote 0

Bill

Member
Licensed User
Longtime User
Well I'm having to do that but why spend time on "creativity in programming" when I want the program to do what I want that's my creative input not ways around problems I shouldn't even have.
It would be perfectly possible to code some assembler behind a goto command Java is only the execution of code behind the instructions, not a sacred cow!
Entry 17.10 in comp.lang.c FAQ list[11] addresses the issue of GOTO use directly, stating:
"Programming style, like writing style, is somewhat of an art and cannot be codified by inflexible rules, although discussions about style often seem to center exclusively around such rules. In the case of the goto statement, it has long been observed that unfettered use of goto's quickly leads to unmaintainable spaghetti code. However, a simple, unthinking ban on the goto statement does not necessarily lead immediately to beautiful programming: an unstructured programmer is just as capable of constructing a Byzantine tangle without using any goto's (perhaps substituting oddly-nested loops and Boolean control variables, instead)."
Guess what here's how to do it http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings.
Yes two or more goto instructions in Java Bytecode.
goto a7 2: branchbyte1, branchbyte2 [no change] goes to another instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2)
goto_w c8 4: branchbyte1, branchbyte2, branchbyte3, branchbyte4 [no change] goes to another instruction at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4)

"The missing "GOTO" that a lot of you are complaining about is missing for a reason."

Yea that reason is nobody's bothered to code it....!
 
Last edited:
Upvote 0

TomA

Active Member
Licensed User
Longtime User

The reason it is missing is because, although it may appear in the Java Bytecode, it is not supported in Java itself. For more background on this see Java Keywords at http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html - note that although "goto" is a reserved word, it is not used. Also, take a look at http://www.javaspecialists.eu/archive/Issue203.html where "goto" is discussed. If you want to see more about it, do a Google search using "java goto" - brings up a lot of hits. "Goto" may be defined in the bytecode but Java itself does not use it. And as I said, Basic4android is converted to Java as part of the compilation process. The resulting Java is what is actually compiled. And since "goto" is not supported in Java, it would be difficult or impossible to add it to Basic4android. A working "goto" would be nice, and I disagree with most of the reasons for not including it in Java (you don't need "goto" to write spaghetti code and you can write beautiful structured code with "goto" - and often create a shorter, and therefore easier to understand, program).

For more background on this, see an earlier post I made at http://www.b4x.com/android/forum/threads/goto-one-day-in-b4a-as-in-b4ppc.17125/#post-136748
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Since I made the original post 2-1/2 years ago, I have written several apps in B4A, including one with with nearly 17,000 lines in it, so I hope that nobody takes the lack of GOTO as a reason not to use B4A.
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
Just a last comment on "goto". It went missing many years ago in some languages because the actual message about it was misunderstood. Reminds me of a message in a book on raising babies - the book said "Never ignore a crying baby", meaning making sure there is actually nothing wrong like a wet diaper, or a pin sticking in, or a sick child, etc., etc. Some people read that and somehow thought that it said "Never let a baby cry" - a totally different meaning and as a result they made their own lives miserable trying to always stop the child from crying, something that sometimes cannot be done. In the same way, the original recommendation/advice was "Limit the use of 'GOTO'" (to avoid spaghetti code) but this was interpreted by some people to mean "Never use goto", hence we have languages where "goto" is not supported, sometimes resulting in code that is more complex and/or harder to follow than it would have been if "goto" had been implemented. Anyone who really wants "goto" implemented, should go after Oracle who effectively now control the Java language.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…