IBM images; building a better Basic. Susan Gilnert-Cole.
IBM Images
Building a Better Basic
Build a better mousetrap and the world will beat a path to your door. This sterling example of marketing maxims does not take into account the fact that the definition of "better,' like many relational descriptors, depends upon which side of the mousetrap you happen to be sitting on. I admit to having been a victim of mousetrap relativity myself quite recently.
Needing some rodent deterrent more effective than two indifferent cats, I spent an interesting hour in the pest eradication section of my local lumber/ hardware/furniture supermarket. The shelves positively dripped with the fruits of legions of mousetrap designers, ranging in style from the humble spring-loader (bring your own bait), to a homey mouse-house furnished with a package of tasty, but lethal, victuals.
In a sudden fit of orginality, probably broght on by the overenthusiastic literature emblazoning the side of the package, I selected a trap best described as a little pan of extremely sticky glue. The entire installation (so the documentation said) consisted of placing the pans wherever the telltale signs of rodent infestation have been appearing and wait for the little critters to cruise into the stuff. Forthwith, they will be stuck fast, and can thus be disposed of, pan and all, without fuss, muss, or bother. Unfortunately, the documentation omitted to mention that mice don't much care for stepping in pans of superglue; they merely waltz around them on the way to the rubber spatula. Thus, these mousetraps confirm the "better mousetrap' theory: they are infinitely better from the mouse's point of view.
Now, if we substitute Basic for mousetrap, we can instantly transport the discussion into the realm of computer science. Several third-party Basics have appeared on the market in the last year. Are they better than the version that comes along with every PC, and if so, for whom?
The IBM PC comes standard with an excellent Basic interpreter and editor in ROM. Disk Basic and advanced Basic provide powerful enhancements to the plain vanilla version and are included with the purchase of PC-DOS. Given the price/performance ratio of the PC's interpreted Basic, one could well ask what could persuade a user to purchase a third-party Basic.
Let's start by considering what features in PC-Basic are weak or absent, and what a third-party Basic might therefore include to mitigate the price differential. For the sake of simplicity, I have broken down the components of Basic into three categories: the editor, the interpreter/compiler, and the debugging environment.
The Editor
PC-Basic has what is known in the industry as a full-screen editor. This means that you can edit anywhere on the screen, in no particular order, by simply moving the cursor around, entering a change, and pressing RETURN. By way of contrast, a line editor allows you to make changes only on a particular line; up and down cursor movements are forbidden or futile. A notorious example of line editors for the PC and EDLIN, a "freebie' supplied with PC-DOS and best left to curdle its code on the DOS master disk. Full-screen editors are preferred for program entry, and the PC-Basic editor is an excellent one.
In the case of interpreted Basic, you must have an interactive edition/execution environment. This is not, however, the case with compiled Basic. In general, compilers do not come with integrated editors, and the manner in which you coax the program into a form the compiler can deal with is left entirely up to your good judgment.
The Interpreter/Compiler
Like all fine tools, these programs should be easy to use, but have enough flexibility for advanced programming. Ideally, they should be bug-free; realistically, any bugs should be minor and infrequently encountered annoyances which are slapped, in a timely fashion, with a software patch provided free by the supplier. The code produced should be efficient and compact.
Nice touches include meaningful error messages, a wide range of extensions, and impeccable documentation. Another desirable feature is dynamic syntax checking, where a program line is checked for syntax errors when it is entered, not when it is executed. (This is a standard feature with Hewlett-Packard Basics.)
The Debugging Environment
This is one area in which PC-Basic falls flat on its nose. The only integrated debugging tool is the TRON command. In general, I haven't found the output from this command informative. Several companies provide utilities for tracing a Basic program and printing a cross-reference listing. This is not only an extra expense, but requires you to work outside of the program development environment. All other things being equal, a compiler/interpreter with good debugging tools has a philosophical price above rubies.
The length constraints of this column make it impossible to give you a good feel for each of five different Basics in a single month. Because each product represents a prodigious amount of work on the part of the software developers, I have decided to examine each Basic individually over the next several months. When they have all been reviewed, I will try to assemble a table summarizing the important features of each.
Professional Basic
This Basic, written by Dr. Neil Bennett, is a product of Morgan Microcomputing. Two other Morgan offerings with which I am familiar are Trace-86 (an assembly language debugging system), and a program editor called TED. My impressions of the company are mixed. They set their sights very high, attempting to include intricate and complex facilities in their products. This naturally represents an enormous investment in development time, but their prices are not unreasonable. On the down side, the implementations are occasionally unpredictable and require some patience for a user to acquire a good comfort level.
Of the three Morgan products, Professional Basic is by far the best. The product is a pleasure to use; it did nothing peculiar during my trial runs. The single anomaly noticed happened after I left the Professional Basic environment: my word processor acted weird, and the system required a reboot to bring it back to normal. Proffessional Basic incorporates features that will elicit constant mumbles of delight from the most jaded Basic programmer: dynamic syntax checking, more than 15 different flavors of debugging windows, and line labels.
The program reviewed here (version 1.0) requires a hefty investment in hardware: at least 256K of RAM (320K is recommended), a 8087 coprocessor, and a monochrome or non-IBM color graphics adapter. (Running Professional Basic with the IBM color adapter generates more snow than August in Antarctica). The next release, promised for the late summer, will not require the 8087 and promises snowless display screens with the IBM color graphics board.
Professional Basic can use all the available memory in your computer. Because array subscripts are 32-bit integers, you can have arrays with up to two billion elements. The maximum number of dimensions is limited only by the 320-character length of a Basic program line. These limits would probably satisfy all but the most dedicated databaser. A trivial, but classy, addition is the elimination of those pestiferous quote marks around file names.
Documentation
The weakest part to Professional Basic is the documentation. It is professionally typeset and comes in a handsome half-sized ring binder, but is written in kind of a stream-of-consciousness style. Specific points are hidden within paragraphs, and it is impossible to pick out information by skimming over the pages. A very careful perusal of the text will usually yield the answer to a question, but I encountered several problems whose solution could not be found in the text, table of contents, or index. The courteous and friendly folks at Morgan will answer any questions left dangling by the documentation, but this won't help the nocturnal/weekend programmer.
The basic premise for this product is quite different from that usually found in language software. Most compilers and interpreters incorporate a series of laconic error messages on the order of "syntax error' or "divide overflow.' They rarely include any provision for examining the program execution other than the brute force approach of sticking STOP statements on each line. The designer of Professional Basic assumes that people usually make mistakes while writing programs and ought to have informative error messages conbined with superior, integrated debugging tools. Evaluated in terms of its debugging environment, Professional Basic is in a class by itself.
Dynamic Syntax Checking
Professional Basic incorporates a line editor with dynamic syntax checking. A press of the spacebar automatically generates a line number or you can type the number in if you wish instead. If you enter something on a line that the editor doesn't think should be there, it beeps at you and the cursor refuses to budge from the offending character. If you press RETURN twice, the set of keystrokes that are valid at that point is displayed. This approach is a vast improvement over picking lines of code apart in search of the vaporous "Syntax Error.' The editor is easy to use; you can zip to the beginning or the end of the line and go from word to word. Deletions can be performed to the end or the beginning of a line, and groups of lines can be zapped at once. A line can be called for editing by typing:
EDIT line number The line just edited can be recalled with F8; F9 moves back one line; and F10 displays the next line for correction. These three keys let you stroll through a file and edit any line that strikes your fancy.
Professional Basic allows the use of line labels within programs. This name, which can be of any length within the 320-character per line constraint, can be used as a reference in GOSUB and GOTO statements. Periods and underscores are allowed within the labels (see Listing 2, line 340).
Another cute feature is "lazy entry.' Instead of typing a variable like SUPER. MEMORY.CLOBBER.ROUTINE over and over, all you have to do is type in enough of the word to identify it, followed by the @ character. If you haven't typed in enough characters to distinguish between several choices, you get a beep, and are invited to type a few more characters.
Professional Basic deals with programs created under another editor with remarkable cleverness. The program, which must be in ASCII format, is checked by Professional Basic during the loading process. When an error is found, a beep is generated, the offending line is changed to include an error message, and loading continues.
Search Facilities
Two helpful search facilities are incorporated into this editor. The first is the FIND command, which locates every reference to a label, variable, or line number. Typing the command:
FIND PRIME
scrolls the lines containing the variable PRIME, highlighted in reverse video, onto the display. Alternatively, the command:
FIND PRIME=
will locate all lines in which PRIME has been assigned a value. Pressing the spacebar presents one line at a time; pressing RETURN resumes full speed scrolling. The search can be abandoned by hitting ESC.
FIND can locate only variables and line labels. Searching for a group of characters is performed with the SEARCH command. SEARCH is particularly useful when you have imported a Basic file from another system that includes code incompatible with Professional Basic. The command:
SEARCH
finds all the lines marked by the dynamic syntax checker as containing errors.
Searching without sorting is something like mink without diamonds. Never fear, Professional Basic has two different varieties of sort commands: SORTV and SORTL. The former will present an alphabetical listing of all the variables in the program while the latter scrolls all the line labels onto the display.
Running the Program
As we all know, typing in the program is a piece of cake compared to the next step: getting the thing to run correctly. In this opaque area of logic analysis Professional Basic really shines.
Listing 1 is the PC-Basic rendition of that unspellable paragon of benchmarks: the Sieve of Eratosthenes prime number generator. Listing 2 shows the same program, converted to Professional Basic. You will notice that Professional Basic, like the PC-Basic compiler, does not allow variables to be used in DIM statements.
Professional Basic creates the debugging environment through the use of windows. Each of the windows presents a different view of the code execution. The windows are invoked by pressing ALT plus some letter. In some cases, however, it is not necessary to prefix the letter with ALT, which can be a bit confusing.
Typing SRUN, for stop run, switches the display to the list trace window (Figure 1). The first statement is highlighted (seen as a horizontal bar when printed). Hitting RETURN causes the program to execute at full speed; the currently executing statement is highlighted in reverse video. Pressing the spacebar causes the system to go into the single step mode. At any time during execution, the windows can be opened and closed, and listed to the printer. Breakpoints can be placed anywhere in the program.
The list trace window has four separate formats, invoked by pressing numbers 1 through 4. Options 2 underlines (or highlights) all the program lines not yet executed. Option 3, shown in Figure 2, shows the number of times each program instruction has been executed. Option 4 (Figure 3) generates a histogram representing the relative frequency of instruction execution.
Some windows can be split. Figure 4 shows the list trace window sharing the limelight with the variable trace window. The total number and the current value of each variable in the program is displayed. The 3/3 says there are three variables in the program and that the third variable is displayed on the screen. If there are more variables in the program than can fit on one screen, the cursor keys can be used to scroll/page through the entire list. Similarly, the current contents of arrays can be examined with the array window (Figure 5).
Figure 6 shows the time trace window on the right side of the screen. This window displays a set of descriptors for each instruction as it is executed. This window has what is poetically described in the manual as "historical rewind.' The descriptors are the program line itself, the sequence number of the instruction, a serial number representing the cumulative number of instructions executed so far, and the variable value and/or assignment, if applicable.
A FOR/NEXT window, shown in Figure 7, displays the active loops, with their current index values. A GOSUB window similarly presents a list of the active subroutines. The DATA window displays a DATA statement with the next element to be read highlighted in reverse video. A FILE INPUT/OUTPUT window displays information currently in the file buffer of each opened file. The data in the file buffer can be toggled between hex and ASCII representation. A memory window lets you look at any area of memory to see what is going on there. At any time during a frantic windowing session, you can view the output screen generated by the program.
Professional Basic is "semi-compiled.' This means that some statements are translated to machine code before they are executed. Semi-compilation falls between an interpreted environment, where program lines are converted as they are executed, and a compiled environment, where all translations are performed prior to execution. The Sieve took PC-Basic 13 seconds to complete. To compile the program, it was necessary to change the DIM and DEFINT statements; the resulting program took four seconds to run with single precision variables. Professional Basic ran it in eight seconds (32-bit integers). I wasn't impressed with the speed, especially given the required 8087 coprocessor.
The version of Professional Basic I worked with did not implement any of the rich graphics or sound functions and statements available in IBM Basics. Neither is there there any provision for interfacing with assembly language: CALL, BLOAD, VARPTR, and the like are absent from the legal list commands. I am promised that the next version will have these features incorporated.
A more serious problem, from a software development point of view, is the lack of a Basic compiler, and the resulting inability to run programs outside of the Professional Basic environment. While a programmer could develop a program in this system and then compile it elsewhere, the Professional Basic enhancements, such as line labels, would have to be eliminated. Professional Basic, at least at this juncture, appeals to two audiences: the person who wants to learn Basic programming and the software developer who doesn't need sound, graphics, or an assembly language interface. As a teaching tool, it is unquestionably outstanding and would be a tremendous asset to the computer neophyte. Given some enchancements, and I expect that Morgan will oblige, it could develop into a superlative development system.
Table: Figure 1. List Trace Window. Plain Vanilla.
Table: Figure 2. List Trace Window. Instruction Count.
Table: Figure 3. List Trace Window. Histogram Option.
Table: Figure 4. Split Screen. List Trace/Variable Trace.
Table: Figure 5. Split Screen. List Trace/Array Trace.
Table: Figure 6. Split Screen. List Trace/Time Trace.
Table: Figure 7. For/Next Window.