Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 11, NO. 10 / OCTOBER 1985 / PAGE 54

True Basic; the creators of Basic show the way. (evaluation) Glenn A. Hart.

Probably the bitterest debates in computerdom concern languages.

Getting IBM PC adherents and serious Apple types together can certainly lead to fireworks (or worse), but for real vitriol try putting a Forth fanatic together with a C devotee, a pistol-packing Pascal virtuoso and a Basic fan. Throw in a Cobol corporation man and maybe an APL freak, and stand back.

Basic is often considered unworthy of serious consideration. The convoluted and difficult to follow code that can result from indiscriminate use of the notorious GOTO command, the lack of branching and looping constructs and procedures popular in structured programming schools, and other weaknesses make most current Basic implementations something of a joke among serious programmers.

Basic was created more than 20 years ago by two Dartmouth professors, John Kemeny and Thomas Kurtz. Since then, their brainchild has become the most commonly used programming language in the world. Now they have teamed up with a group of young whiz kids to produce True Basic, a new programming language which they hope will become the standard dialect of Basic.

True Basic is beautifully packaged, elegantly designed, and easy to use. The True Basic environment splits the screen into two windows, an Editing Window for entering and modifying programs and a History Window for commands and program output.

True Basic programs are written and modified with a full-screen editor which uses cursor control keys and control character sequences. The commands are not totally standard compared with most other PC programs, but they work fine and don't take long to learn. Complete find and replace provisions are included, a major advance over the simple editor provided with Microsoft's BasicA. Blocks of text can be marked and then moved, deleted, indented, edited as a group, etc.

The best feature of the editor is RESTORE, which replaces text after an inadvertent deletion. True Basic restores only while the cursor is positioned on the line where the mistake was made, but it is much better than nothing.

The editor uses function keys to invoke several common commands, and True Basic also uses function keys to move back and forth between the editing and history windows, run programs, etc. A key redefinition provision allows you to change the key layout and is much more sophisticated than the simple function key redefinitions available in BasicA.

True Basic acts like a Basic interpreter in some respects and like a compiler in others. Like an interpreter, it allows several commands to be issued at the command line (LET, ASK, PRINT, SET, etc.). Variables are "active" after running an "uncompiled" program, so this "direct" mode can be used for debugging by examining the value of variables when a program is interrupted.

Once a program is entered or recalled from disk into the Editing Window, it can be run. If the program is in source form, True Basic first compiles it to an intermediate code and then invokes a special interpreter to execute the code. The semi-compiled code can be saved to disk, in which case True Basic won't have to take the time to perform the compilation the next time that program is called.

The True Basic language itself is modeled on the proposed ANSI standard Basic, which is quite different from the Microsoft Basic which has become a de facto standard on microcomputers. Professors Kemeny and Kurtz have written an enjoyable book called Back to Basic which discusses the differences. Both the various design decisions that make ANSI/True Basic unique and the Microsoft style, which the authors deplore, are analyzed in complete, if perhaps biased, detail.

Adding Structure

The main objective of True Basic is structure, the process by which programs are designed and implemented in a modular manner which improves readability and maintainability. Structured programming has become a basic tenet of computer education, and also allows smoother implementation of large programs. True Basic includes structured programming constructs superior even to those of Pascal or C.

True Basic programs normally do not use line numbers; they employ new, improved branching facilities, although line numbers and most of the old style branching statements are allowed. If even one line has line numbers, then all lines must be numbered. Routines to add, remove, and renumber lines are included. Various True Basic commands can use line number ranges or block names or a combination of both. Variable names can be up to 31 characters long. LET must be used when values are assigned to variables. Only one statement can be on a line. For the most part, True Basic makes no distinction between integer and floating point numbers, and no trailing symbols are used to indicate numeric precision.

Conditional branching can be performed with either single line simple IF-THEN and IF-THEN-ELSE statements or more complex multiple-line IF-THEN-ELSE-END IF structures. True Basic is reasonably rigid on where clauses go, but improved structure and readability usually result. True Basic also includes a multi-branching switch construct SELECT CASE statement complete with ELSE (like the OTHERWISE clause often used in Pascal). SELECT CASE creates much more readable code than a series of IF-ELSE statements.

True Basic offers an excellent assortment of loop constructs. The FORNEXT design is standard, although no potentially confusing fanciness like omitting the variable name after the NEXT or terminating multiple FORS with one NEXT is allowed. The other loop constructs provided are DO UNTIL cond - LOOP, DO - LOOP UNTIL cond, DO WHILE cond - LOOP, and DO - LOOP WHILE cond. The UNTIL-type statements and the WHILE-type statements can perform the same functions (the logic of the condition being tested would simply be reversed), so the choice is a matter of style.

EXIT DO and EXIT FOR statements allow exiting from the middle of a loop to the line immediately following the loop. These statements can result in much more natural code than some of the convoluted constructions sometimes required by "pure" structured methods.

DATA and READ work normally, but with some interesting wrinkles. MORE DATA and END DATA clauses are provided to make reading data easier (e.g., DO WHILE MORE DATA). RESTORE is available, but there is no RESTORE to a specific location or line number.

True Basic arrays must be declared with a DIM statement; there is no default to a ten-element array size. As in Pascal, both lower and upper array bounds can be specified, so a statement like DIM X(1980 to 1990) is both descriptive and permitted.

Array access is light years ahead of most microcomputer Basics, because a full assortment of MAT statements, which manipulate arrays without cumbersome nested FOR-NEXT loops, are provided. MAT statements have been available on some mini and mainframe Basics, but not normally on micro-computer implementations. True Basic includes MAT READ, MAT PRINT, MAT INPUT, and MAT LINE INPUT statements as well as MAT arithmetic functions.

One of the worst "features" of old Basic is that all variables are global, i.e., accessible to the main program as well as any subroutines. This can lead to all kinds of subtle bugs, artificial constructions, and more. True Basic remedies this situation by allowing subroutines and functions to have parameters. Both single line user-defined functions like those in Microsoft Basic and multi-line functions as in CBasic are allowed. If subroutines and functions are defined prior to the END statement in a program, they are referred to as "internal" routines and their variables are global. The same routines and functions defined after the END statement are external, and their variables are local to the subroutine or function. Parameters are passed to functions by value and to subroutines by reference. Both functions and subroutines can be used recursively. True Basic even allows arrays to be passed to both functions and subroutines. External assembly language routines can also be accessed.

Subroutines and functions can be grouped together into external libraries, an advanced feature which can be used for structure or to distribute functional code. True Basic is supplied with four powerful libraries for advanced numeric computations and graphics, and several more libraries are being developed for future distribution.

True Basic string manipulations differ markedly from the Microsoft style. The True Basic string commands are sometimes more readable and sometimes less so, but LEFT$, MID$, RIGHT$, and other familiar functions can easily be programmed if desired.

Graphics and Sound

True Basic graphics are also quite different from and superior in many ways to those in Microsoft Basic. Unlike IBM PC BasicA, which uses coordinates based on the pixels available on the PC screen, True Basic can set any edge coordinates desired and will draw in terms of this view. The commands available cover a wide range of both simple and complex graphics manipulations. In addition to various fast point, line and box drawing routines, True Basic PICTURES are like graphic subroutines and can have parameters for modifications at each call. Five "transformations" are available to slide a picture, change its size, scale, rotate, or lean a picture. True Basic can also establish windows, but these (like the other graphics features) are available only on color systems.

Music and sound are easily created with a PLAY command which uses a very simple and straightforward notation for music, including such niceties as dotting, legato and staccato attack, and more. A more traditional SOUND command is also available for specifying frequency and duration.

Other language features add clarity and simplicity. The True Basic INPUT statement makes operator prompting clear and consistent. A KEY INPUT clause indicates when a key has been pressed for good interactive control. SET CURSOR and ASK CURSOR statements position the cursor, turn it on and off, and query its position. True Basic PRINT USING facilities are similar to those of Microsoft Basic but with a few differences and advantages. For example, left and right justification and centering are available when strings are formatted. A CHAIN command allows you to run another program, although the ability to pass information to a subsequent program is rather limited. True Basic error handling allows you to "protect" a block of code with an error handling routine. The error handling is more flexible and better structured than in BasicA and most other Basics.

True Basic manipulates three kinds of disk data files. BYTE files have no structure and can be considered as simply streams of bytes that can have any arbitrary, user-defined format. RECORD files are fixed length data files. TEXT files are stored in standard IBM text format for use by any PC application. True Basic RECORD files are portable to any computer running True Basic (as are any True Basic Compiled B-Code program files).

File manipulation commands include OPEN (assign a channel to a disk file), CLOSE a channel, ERASE (delete the contents of a file), UNSAVE (delete a file itself), SET file attributes, and ASK to determine the attributes of a file. Ten files can be open simultaneously. Channels can be local or global, much like variables; an external function or subroutine can have its own channels, which close automatically when the routine is exited.

The OPEN statement has clauses to set ACCESS mode, CREATE mode (whether to use an old file or create a new one), ORGANIZATION (the file type: text, record, or byte), and the RECSIZE. The SET command can change the MARGIN (actually its line length), ZONEWIDTH (the tab settings used when commas separate field output), or RECSIZE of a file.

The ASK statement is a powerful command which can determine many attributes of a file, including its access mode, file size, margin, name, organization (type), pointer location (beginning, middle, end, or, alternatively, exact record or byte count), recsize or zonewidth.

Use and Performance

To test the performance of True Basic, I first ran the Sieve of Eratosthenes prime number program at the standard ten iterations and the Creative Computing simple numeric benchmark for True Basic, the Microsoft BasicA interpreter, and the Microsoft Basic Compiler. The results of the tests, which were run on an IBM PC AT, appear in Tables 1 and 2.

Both of these benchmarks indicated that the semi-compiled True Basic is significantly faster than the BasicA interpreter--perhaps ten times as fast and with better accuracy. On the other hand, True Basic is simply no match for a good native code compiler like Microsoft's Basic compiler.

I then translated the disk drive testing benchmark developed by Mike O'Cone of PC magazine. While this is normally used to test computer/drive performance, I felt it could shed some light on disk access differences between languages. This guess was confirmed, because the differences were dramatic. Using 128K sectors and writing and reading randomly and sequentially a 200K data file created on a RAM disk to eliminate mechanical factors, I got the results shown in Table 3.

The developers of True Basic informed me that many sections of True Basic are written in True Basic itself, which helps portability at the possible expense of speed. It appears that I hit a nerve with the disk access routines, which clearly should be rewritten in assembly for better performance.

The translation process was informative in itself. The editor is easy to use and reasonably flexible, although I wish it retained indentation on subsequent lines as the Turbo Pascal editor does. When an attempt is made to compile and run the program, True Basic positions the cursor at the exact location of an error and displays an English error message. This is an excellent feature, which greatly eases accurate program entry and development. On the other hand, the program cannot be run at all until all errors are removed.

True Basic includes a BREAK-CONTINUE mechanism as a debugging aid, but the debugging tools are not as powerful as those of Morgan Professional Basic and some other advanced BasicA utilities. Unfortunately, the TRACE facility standard with Microsoft Basics is lacking in True Basic. Overall, the debugging assistance must be classified as fair at best.

The syntax differences between Microsoft BasicA and True Basic were not as bad as I had expected. The True Basic file syntax is much better than Microsoft's, but the language design is still not as clean in this regard as CBasic. A programmer should not have to count field locations--this is the kind of thing a computer does well. The authors of True Basic blame this on the deficient ANSI standard, but perhaps they should simply bite the bullet and design their own procedure.

Because True Basic program files are straight ASCII, WordStar and/or a keyboard macro program like Prokey or SuperKey could be programmed to help semi-automate conversions. The True Basic team is working on a conversion assistance product, which we will review when it is released.

I was excited by the character by character access which byte files allow. Previously, a Basic programmer had to LINE INPUT a line of text and then use MID$ to work with individual characters. To test byte access I wrote a program that converts WordStar files to standard DOS files. The program worked the first time, but was definitely on the slow side. It proved to be faster to use the older technique and use the True Basic line$[i:i] (like MID$ in BasicA) for the strip.

I also tested the Binder which allows commercial software houses to produce stand-alone executable files. The binding process itself was quick and painless, but a 44-byte source file (to issue a formfeed to the line printer) became a 63,622-byte .EXE file. Microsoft's BASCOM created a stand-alone executable file which performed the same function in 17,792 bytes. A True Basic executable version of the Sieve took 63,898 bytes, so obviously the run-time interpreter takes up 63,000 bytes or so. I have heard of overhead, but this is ridiculous!

As comprehensive as True Basic is, there are also some reasonably serious omissions too. As mentioned, the True Basic RECORD file is really a string file system, so the file system is awkward. True Basic does not support communications ports, because "After all, True Basic is designed to be identical on every computer, and communications ports are quite different among various computers." The manual suggests using assembly language, which is way beyond most users. The developers of True Basic indicated to me that this flaw would be rectified in a future library. Similarly, there are no hex number facilities or DOS access routines; these are being rectified in libraries as well. The mouse facilities were left out of the IBM version, but evidently will be added later, etc. The language system would benefit greatly by the addition of a fast native code compiler.

The documentation is simply superb. Two manuals, totaling over 600 pages, are provided. The True Basic User's Guide is an excellent introduction to the language and its use. Each chapter begins with a statement of goals and a glossary of the terms introduced and ends with a succinct summary. The writing is clear, easy to understand, and never condescending, and provides a fine tutorial on Basic itself as well as the True Basic dialect. The Reference Manual is equally good, and both documents include a detailed and usable Index.

A New Standard

The True Basic team asserts that the "American National Standard for Basic will be the standard form for Basic for years to come." This is quite a conjecture for a standard that hasn't even been officially released. They hope that the language's portability, use of the full IBM PC memory space rather than the limited memory model used by Microsoft, use of the 8087/80287 math coprocessor if present, the context sensitive on-line help system, the comprehensive editor, etc. will be important factors.

The main problem is that Microsoft Basic has been around so long in its various dialects that it forms a tremendously powerful de facto standard. Microsoft is an entrenched competitor that will be exceedingly difficult to unseat. Add to this the fact that while the True Basic price of $150 is exceedingly reasonable, BasicA on the IBM PC is free. Neither is there any law forbidding Microsoft to change and improve. Their new Basic for the Apple Macintosh (see Creative Computing, May 1985) is exploring some of the same approaches used by True Basic. If Microsoft decides to issue an ANSI standard Basic in the future, True Basic could be in trouble.

True Basic is unquestionably an excellent language. It is powerful, friendly, and easy to use. If someone could wave a magic wand and replace every copy of a Microsoft Basic of one sort or another with a copy of True Basic, I think the computing world would be a far better place. Whether the True Basic team, even with famous heavyweights like Kemeny and Kurtz involved, has the clout to unseat the current champion remains to be seen.

Products: True BASIC (Compiler)