Sunday, December 28, 2025

Revival of BASIC

BASIC, the language of my youth (quickly replaced by F0RTRAN), came back in a surprising way. 

Some months ago, a PicoCalc finally arrived at my doorstep. The kit is brilliant and so is the product.
I toyed with the Lisp interpreter as an RPN calculator... fantastic! However, most of my readers are probably not interested in either RPN (reverse Polish notation) or in Lisp (and probably not in F0RTRAN either).

So, today I want to share some views of mine using the MMBASIC, which is part of the PicoCalc package.
MMBASIC allows for classical line numbering. We all know how convenient that is. Also, the line numbering BASIC code often leads to some severe spaghetti-code.

MMBASIC however, also allows for a more modern approach w/o line numbers, but labels instead. Generally labels are great, however, one needs to be careful to avoid any keywords when choosing labels.

In a label based programming language, one obviously wants to focus on routines to avoid spaghetti code. As know from many programming languages, such (sub)routines (procedures, functions or whatever the name is) usually are coded before the main program loop. BASIC does not respect this convention, first come first served in the doctrine here. 

Here is how to overcome BASIC's ignorance.

I usually have a block of constants and variables at the beginning of my code. That's cool with BASIC too.
In my usual programming, routines come next. BASIC would usually just start executing those and spit out an error when the first "return" was encountered. Fair enough, a return without a call cannot be performed.

In order to keep the traditional order of routines and functions before the main program loop, we need to pull a trick.
Similar to what is done in C, my main program loop in BASIC (at the end of the code) will get a label main:. So, the very first command after the definition of constants and variables is goto main. Obviously, this forces the interpreter to directly execute the main-loop.

I am not sure if this is elegant, however, this is how I program in modern BASIC.