basicqbasicgw-basic

Explicit line numbers and execution order


GW-BASIC and many other old BASIC dialects like C64 BASIC allowed you do something like this:

20 PRINT "World"
10 PRINT "Hello"

and that would result in the following output when the RUN command/statement was executed:

Hello
World

The LIST command/statement would list the program:

10 PRINT "Hello"
20 PRINT "World"

In other words, those BASIC dialects would automatically re-order the execution to fit the order specified by the line numbers you used, regardless of the order in which you originally typed/saved them in another editor (e.g. EDLIN.EXE). However, QuickBASIC and BASCOM2 failed to do the same.

The oldest QuickBASIC version I could find online was QuickBASIC 2.0, and it didn't work there, simply ignoring the line numbers to print things in the order I wrote them (i.e. "World Hello").

BASCOM2—the oldest MS/IBM BASIC compiler I could find—also apparently didn't support the feature, instead failing with an error (SQ = Out of order sequence?):

 0046   0006    10 PRINT "Hello"
                ^ SQ

50434 Bytes Available
50325 Bytes Free

    0 Warning Error(s)
    1 Severe  Error(s)

While I certainly understand how often line numbers are superfluous, it seemed like a useful feature to support execution in explicit line number order (20, 10, 30 => 10, 20, 30) rather than implicit line number order (20, 10, 30 => 20, 10, 30).

Does anybody have any idea why this traditional BASIC behavior was ignored?


Solution

  • I'm surprised that the first bascom you found reported an error. All compilers that I've ever used for BASIC, and I believe I've used a lot of them since 1982 on, made line numbers optional and supported labels. I remember that in my first job as a professional programmer, we designed a compiler pre-processor that would insert only lines needed for proper IF, ELSE IF and END IF statements by replacing stuff with line numbers and (gasp) GOTO statements.

    I still use line numbers today in my still supported VB6 accounting application thanks to MZ-Tools add-in that allows me to add and remove line numbers to my methods and function with a single button click. This allows me to use Erl (error line number) in all my error routines, also a quick one-button add to all my methods and functions, which allows me to pin-point the exact line any error occurs on.

    I'm sure the compiler designers thought that line numbers were only of real use to interpreters, and perhaps the first version of bascom figured you'd develop and test with an interpreter, then compile and distribute the executable, then perhaps later versions figured developers were using text editors, especially the later versions that came with their own IDE's and who would need line numbers there? Well, we do if we want precise error reporting! That's one thing I like about Java and Eclipse. The line numbers are there so I can know exactly where the errors are, but they don't get in the way like they do in BASIC (remove line numbers, add/remove code, replace line numbers).