Basic is back. (computer language; includes related articles)
by Tom Campbell
It wasn't supposed to work out this way. By now, BASIC should've been history. In the late 1960s, Pascal was expected to have knocked off BASIC. In the 1970s, C was touted as the BASIC killer. These languages were miles ahead of BASIC.
Little wonder the fans of emerging languages had little good to say about it. BASIC was unstructured, claimed the partisans of Pascal. It was too much like FORTRAN, observed the C wizards.
And they were right. But the reports of its demise were premature. BASIC, like Rocky with a pocket protector, keeps coming back with astounding resilience.
History Lesson
BASIC was created in the early 1960s to give Dartmouth College students a way to use computers easily without becoming experts in FORTRAN. BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. And while they weren't very good at dreaming up convincing acronyms after the fact, BASIC's creators, John Kemeny and Thomas Kurtz, could invent languages like nobody's business.
It's impossible to overstate the effect BASIC had on the computing world. Almost everyone - whether involved in programming or computers or not - recognizes the name of the language. Even the uninitiated can learn a few BASIC statements in a short time.
Back Talk
BASIC is interactive. When it was introduced, the mere fact that you could type in BASIC statements at the terminal was revolutionary. Real byteheads wrote their programs a week in advance, painstakingly typing them out n IBM cards that looked like airline suitcase tags gone bad and submitting them to the computer's operator, who would then run the cards and see that the resulting printout was returned to the programmer eventually. BASIC changed all that. It took a computer that was a distant, cloistered beast and turned it into a friendly intelligence with which programmers could directly interact - in terms not very different from conversation (or at least not very different from a conversation among byteheads).
Not only it is interactive, but BASIC (unlike most other languages available at the time of its creation) was not hideously difficult to learn. Take variables, for example. Variables in computer languages are something like the variables that gave you nightmares in high school algebra (as in 4X + 2 = Y), but they're more useful and less threatening. In PL/1, another computer language, if you wanted to use a variable, you had to warn the compiler in advance that you'd be using it. You even had to say how many bits it took up. BASIC is more tolerant. If you need a variable, just start using it - BASIC handles the bookwork.
The original BASIC, introduced in 1964, was primitive by today's standards, but it was profoundly influential. It spread like measles through the programming world, which at that time was entirely concerned with minicomputers and mainframes.
Meanwhile, as Kemeny and Kurtz take pains to point out, Dartmouth's BASIC was not their brainchild, but its mutant, obsolescent offspring. For example, the requirement that each line begin with a number was dropped early on in the Dartmouth version, but line numbering was still common practice until 15 years later, when Microsoft released Quick BASIC was
A more important differences lies in the fact that Dartmouth BASIC wast compiled from the start, but it was compiled so quickly that it was invisible to the user. In short, it looked as if it were interpreted.
The difference is that compiled code is completely converted into a form the computer can read directly, and therefore it runs much more efficiently. Interpreted code is read by a second program called an interpreter, which then instructs the computer in its own language, telling it how to go about following the commands in the BASIC program. The result is slower, less efficient execution. Another near-fatal shortcoming of interpreted BASIC is that you normally can't distribute an interpreted program and expect it to run on the target machine because it needs the interpreter. Compiled programs, on the other hand, are self-contained. Dartmouth BASIC had the immediacy of an interpreted language, but it was a compiler - again, a feature that would not see implementation commercially until Quick-BASIC was released in version 4.
BASIC got a bad rap from academics and computer snobs even as it was making spectacular progress, much to the frustration of its creators. All involved in the controversy seemed blind to the fact that BASIC was by the far most popular language in the world by the time the IBM PC was introduced.
The Language
BASIC is the Swiss Army Knife of computer languages. Like that versatile tool bristling with corkscrews, trimmers, and a toothpick, BASIC is adequate to accomplish just about any small task you'll run across in the field.
Likewise, if you have a big programming job, you'll probably find other languages better suited to your task. Modern versions of BASIC (QuickBASIC, Power BASIC, or True-BASIC, but not the free BASIC-probably BASICA or GW-BASIC - that came with your copy of DOS) can legitimately be regarded as stepping stones to other languages.
All the concept inherent in more advanced languages can be employed in BASIC.
BASIC is probably used professionally by more contractors than any other language. If your company wants to computerize its inventory system, needs a terminal program written to let customers jack into your proprietary BBS without having to learn a communications package, or needs to have a one-time program written to convert your mainframe data to dBase format, there's a good chance that the person you hire will write that program in BASIC.
BASIC is increasingly popular as an embedded language. A multi-million-dollar California firm called Pick Systems has for years existed solely on a hybrid operating system/database manager, and the language users work with is Pick BASIC, a variant of BASIC that allows end users to write some pretty hairy relational database code in very few lines - without having to call in the company guru.
Bill Gates of Microsoft has long threatened to make BASIC a common language to bridge Windows and OS/2 applications, and the latest version of Microsoft's powerhouse word processor, Word for Windows, actually has a BASIC interpreter to supplement its macro language.
For years, Digital Equipment's smaller computers were powered by an operating system with BASIC as its user interface. VAX BASIC, Business BASIC, and HP BASIC are all hugely popular in the minicomputer world, but this fact is treated like a dirty secret. A company in my vicinity sells turnkey CAD systems with a CAD program written in 250,000 lines of VAX BASIC. The price for the lowball configuration is $100,000.
Why Use BASIC?
Despite its reputation, BASIC is great for a large variety of applications. There are dozens of good books on BASIC; there's no shortage of BASIC programmers around. A lot of great programming tools are written with BASIC programmers in mind, and it's a forgiving programming environment. BASIC is good for one-time-only projects, medium-sized projects where getting the job done quickly and on a small budget is important, communications programs (BASIC has facilities built into it for communications that would take a good C or Pascal programmer weeks to duplicate), database managers, high-precision math for dollar or other decimal amounts, and programs where a slick user interface is important.
Nor can I resist pointing out that programming in BASIC is fun. After years of programming in C professionally, I still find C less fluid and enjoyable to work with than BASIC, although the demands that C places on a programmer have made me a much more capable one.
Why Not Use BASIC?
There are times to avoid BASIC. If you want your program to have portability (the ability to run the same program on many machines), you won't want to use BASIC. With careful planning, nothing beats C (and even older versions of FORTRAN and COBOL) for code that has to run other machines.
C was designed with portability in mind. FORTRAN and COBOL are popular enough that lowest-common-denominator versions will work on just about any computer.
Group projects are another reason not to use BASIC. BASIC doesn't make you declare variables, which can be a liability on large projects where BASIC's innocent habit of creating a new variable when you've actually mistyped the name of an existing one can pose horrific maintenance problems.
Finally, programs that require dynamic memory allocation also extend beyond the scope of BASIC, which is sadly lacking in memory allocation/deallocation routines similar to malloc() and free() in C, or New and Dispose in Pascal or Modula 2.
Meet the KIng
The undisputed king of microcomputer BASICs is Quick BASIC, which is widely credited with pulling BASIC back from the edge of doom. It didn't. The installed base of BASIC code was far too immense for that. (My theory is that QuickBASIC's wide recognition is due to the fact that journalists, who never really understood C, found that legitimizing QuickBASIC in this way meant that they could justify viewing themselves as serious programmers because even they could program in it.)
Built for comfort and speed, QuickBASIC is like a Mercedes: engineered so well, built so right that using it is an experience verging on the sensual. QuickBASIC, was always a compiled language, but BASIC compilers were nothing new. Starting with version 4, QuickBASIC, like its ancestors Dartmouth BASIC, offered an evnironment that looked interpreted but offered true compiled programs by compiling on the fly.
One of the problems with compilers is that they normally operate in a sort of batch mode. You write a routine and then run it through the compiler - a process that usually takes a few minutes but can take much longer, depending on the compiler. If the routine passes muster, you run it a few times to shake the bugs out and start the cycle all over again when you begin to write the next routine. When you have enough routines, you've written your program. Programming can take on a routinized, recursive aspect that tries one's patience.
Interpreted BASIC leaves the bad part out. Using an interpreted BASIC, you write your program, press the Run key, and voila! Instant gratififcation The program runs without the bothersome compilation step.
Quick Solution
QuickBASIC skirts problem by compiling in the background as you type. The code it compiles to isn't really machine code, so it's not as fast as native code - that is, a program the processor can run directly - but it's fine for testing purposes and much faster than older interpreted BASICs such as GW-BASIC.
When you've debugged your program, you can choose a menu option to create an EXE file. QuickBASIC runs a rapid compiler to create the final executable program file. In other words, QuickBASIC provides all the fun of the old BASIC and the advanced compiler technology of a company that's been in the BASIC compiler business for almost a decade. It's an unbeatable combination.
Nonetheless, Microsoft goes even further. QuickBASIC comes with strong graphics abilities, standard-setting online help and tutorials, slick mouse support, and the ability to write much larger programs than you can in traditional interpreted BASIC. My only gripe is that Microsoft expects you to rely on online help or purchase a $25 book (from - you guessed it - Microsoft Press) for reference. There is no printed reference manual provided with the language.
On the other hand, maybe QuickBASIC isn't unbeatable. Maybe BASIC 7.1 beats it.
The Prince
If QuickBASIC is the king of the BASIC market, Microsoft BASIC 7.1 has to be the prince. At $495, it lists at almost $400 more than QuickBASIC, but it's worth every dollar. For one thing, you get the manuals. You get two interactive, QuickBASIC-like programming environments: QBX, which is almost indistinguishable from QuickBASIC, and the Programmer's Workbench, an underdocumented but infinitely flexible system that's more than an editor and sligthly less than an expert system. Programmer's Workbench also works with Microsoft C and is clearly a glimpse of the future of Microsoft programming environments.
BASIC 7.1 has support for OS/2, more options regarding program and data size, code optimization, and new additions to the language for currency (most computer languages, C and Pascal included, don't have good support for decimal math with many digits of precision). There's text-mode user interface library with unltrafast screen updating, windows, buttons, data entry, and mouse handling. Intriguingly, the manual explains that it's designed to look like the Macintosh version of the language, and instructions are provided to port between versions. The graphics library is far deeper than QuickBASIC's, notably offering Windows-compatible fonts that you can package with your program if the user for whom you're developing programs doesn't have them.
My favorite addition to BASIC 7.1 is the ISAM library. ISAM, which stands for Indexed Sequential Access Method, is a file-indexing method used by high-powered database programs; ISAMs offer unmatched speed and flexibility for large databases. While I haven't had a chance to test their assertions, the manuals throw around figures like 128 megabytes for a database and more indexes than a good application should ever need.
While the graphics and user interface libraries are add-ons, ISAM is built into the BASIC 7.1 language; several command line options and compiler directives are solely for ISAM. Even if you don't need things like OS/2 code generation or hacker-level tools like the Programmer's Workbench, the extras in BASIC 7.1 could save you a fortune in third-party libraries. Better still, third-party developers are now building on the foundations laid by BASIC 7.1.
Contenders
While Microsoft has just about sewn up the BASIC market, there are other BASICS. And they're good. In fact, they're very good.
Turbo Basic/PowerBASIC, A few years ago, Borland acquired a version of BASIC from ace programmer Bob Zale. Borland released it as Turbo Basic, but, unlike Turbo C and Turbo Pascal, Turbo Basic was unable to remain a serious contender.
I like Turbo Basic. It has a programming environment like the other Turbo products - awesome link speed and the most agile integrated editor around - but with a native-code compiler as the only option. While it compiles much faster than QuickBASIC, there's still a wait. The online help is good, but not as good as QuickBASIC's. It's solely lacking in examples and cross references, but it does the job. The language was left untouched while QuickBASIC went through several brilliant revisions. Borland recently laid it quietly to rest and returned the rights to Zale, who has updated it and released it as PowerBASIC (Spectra Publishing).
PowerBASIC is screamingly language extensions like ARRAY SORT, ARRAY INSERT, and many incremental but wise improvements on string handling. I'd been wanting to write a program that displays a directory by extension, but I hadn't gotten around to it. C has library routine for sorting, but access to DOS is spotty. Turbo Pascal has good access to DOS but no library routine for sorting. PowerBASIC gave me everything I needed. This is the most important criterion in selecting a language.
PowerBASIC is screamingly fast - quicker than its Turbo predecessor and close to QuickBASIC even on large programs, thanks to separate compilation via units. Units in PowerBASIC are less powerful than those in Turbo Pascal and Modula 2, but they do make separate compilation faster than with OBJ files.
PowerBASIC has updated help and also fits nicely on a floppy-only laptop system.
True BASIC. The rather tardy attempt by Kemeny and Kurtz, BASIC's Dartmouth-based originators, at cashing in on their creation is True BASIC. This language is closely based on ANSI BASIC. (America's standard organization has had a BASIC on its books for years, which may explain why True BASIC hasn't set the world on fire.) Core True BASIC runs on many machines including the Mac, Atari ST, and PC. Its main values are its portability and close adherence to the standard. It's a good choice if you're an engineer who wants to run the same program on many different machines.
Embedded BASICS
There are many versions of BASIC on the PC that come as support for another application and aren't sold as stand-alone languages.
Pick BASIC. As mentioned before, the native language of the Pick operating system is Pick BASIC. On the theory that database management is the main task of many computing systems, Dick Pick wrote his own operating system that used BASIC as its script language and user interface. The idea was sound but of limited application, and Pick has recently branched out into other operating systems, selling Pick as a database manager that can run under UNIX, PC-DOS, VMS, or whatever.
RBASIC. RBASIC is the language that comes with the muscle-bound database manager R:BASE. It's modeled after Pick BASIC, but R:BASE has been running under DOS a lot of longer than Pick has.
Structured Programming in the Spotlight
You've probably heard the phrase structured code juxtaposed with the phrase spaghetti code. Here's the good, the bad, and the ugly about spaghetti code. Especially the ugly.
Older versions of BASIC on microcomputers - quite possibly, the BASIC that turned you away from coding - were sharply limited in the ways decisions were handled, often being limited to IF/THEN statements. We'll illustrate this in a moment, but first take a look at some of the new choices available to you now. Even if you don't know what they mean, it's enough just to see the variety: SELECT CASE, WHILE/END, IF/THEN/ELSEIF/ELSE, and DO/LOOP, to name the major alternatives.
BASIC's SELECT CASE is even better than Pascal's and C's. It lets you make choices based on string constants, string variables, string expressions, numeric constants, numeric variables, numeric expressions, and subranges. Pascal offers only numeric constants and subranges. C offers only numeric constants.
Who cares? You do, because the only alternative to IF/THEN in older BASICs was to use tons of GOTO statements. GOTOs used in placed of real control structures such as SELECT CASE cause horrifying maintenance problems because constructs like IF/THEN/ELSEIF/ELSE/ENDIF are replaced by IF NOT.../GOTO 100 GOTO/ 110/GOTO 120/GOTO 130.... You end up haaing to figure out what line numbers to go to. Later, if you have to modify your code, you'll end up wedging lines 17 and 18 between lines 16 and 19.
Below is a concrete illustration, excerpted from a recent program I wrote. The first example shows the structured version. It contains no GOTOs (meaning I didn't have to keep track of line numbers) or long variable names (since modern BASICs aren't limited to two characters for variable names as old BASICs were). And I could use meaningful subroutine names like IsAlpha% or IsPrint%, rather than undescriptive line numbers.
Structured BASIC:
'The QuickBASIC version: IF StrSize = 0 THEN
IF IsAlpha(NextByte$) THEN
StrSize = 1: Word$ = NextByte
END IF' IsAlpha ELSE
IF IsPrint%(NextBytes$) THEN
StrSize = StrSize + 1: Words$ = Word$ + NextByte
ELSE
StrSize = 0: Words = " "
END IF END IF' IF StrSize = 0
Unstructured BASIC:
5 REM The "street BASIC" version: 10 IF SS <> 0 THEN GOTO 100 15 GOSUB 300' IsAlpha equivalent routine. Sets global IA. 20 IF NOT IA THEN GOTO 60 30 SS = 1: WD$ = NB$ 35 GOSUB 400' IsPrint equivalent routine. Sets global IP. 60 IF NOT IP THEN GOTO 100 70 SS = SS + 1:WD$ = WD$ + NB$ 90 SS = 0: WD$= " " 100
ASIC: The Beginner's Inexpensive Alternative
On this issue's disk, you'll find ASIC, a shareware BASIC with a registration fee of only $10. It's a true compiler that generates small COM files and doesn't need GW-BASIC or QuickBASIC, so you can embark on your first adventures in compiled languages at a great price. BASIC power users need not apply: ASIC is an entry-level product at a fair price, but QuickBASIC, True BASIC, and PowerBASIC have nothing to fear. Yet.
ASIC is a fast in-memory compiler with an integrated editor and no link step. You normally work from the editor screen and compile from within the environment, but ASICC. EXE, a command line version of the compiler, is included for diahards like me who can't part with their own editors. This is a thoughtful item that shows foresight. Programming languages shouldn't tell you how to work.
The ASIC languange look much like traditional BASIC without line numbers. While you can use line numbers if you like, the preferred syntax is to labels for GOTO and subroutines. Instead of constructions like this:
GOSUB 11000 ... GOTO 650
you have the luxury of much more descriptive labels, like this:
GOSUB DisplayScore: ... GOTO Initialize:
ASIC's integrated editor is small but useful. It supports the fundamental operations needed by the language. The fact that there is any sort of an editor bundled with a $10 compiler is miraculous. You can load, save, and compile ASIC programs from within the editor. The editor isn't line-oriented like EDLIN but is full-screen like the Turbo Basic editor. It's capable of block operations for copying, moving, and deleting text; has search and replace functions; and lets you jump to errors in the compiled source code.
One ASIC feature you will rarely see in any integrated environment is its symboltable generator. The symbol table is an alphabetical listing created during compilation that shows the location of all subroutines and labels. It's one of those things that every compiler should have but doesn't.
ASIC does lack some features. It doesn't support READ/DATA statements. There's a MID$, but no LEFT$ or RIGHT$. (That's not as bad as it seems, since you can do the equivalent of LEFT$ or RIGHT$ using MID$, but the reverse is not true.) There's no PLAY statement, although SOUND is available. Because ASIC uses integers only, you may miss floating-point numbers. On the plus side, integer math is many times faster than floating-point math.
ASIC was written using TURBO C, and its C roots show in file I/O/. File I/O is limited to text mode, and string variables are fixed-length 80- character arrays ending in a 0 byte. LPRINT, PRINT #, and INPUT # let you manipulate these files. OPEN and CLOSE let you perform the housekeeping.
I was delighted to find a memory map in Chapter 8 of the manual; this map gives the location of ASIC system variables so that you can poke and peek them at runtime. Whereas other compiler make this information strictly off-limits to developers (they're actually warned away from such behavior), ASIC encourages it. That's real programming! Like the command line version of the compiler, it's the kind of thoughtful touch that keeps users coming back for new versions. You can tweak such values as the random seed, cursor position, screen width, and input buffer with the utmost safety and confidence. naturally, PEEK, POKE, DEFSEG, and VARPTR are implemented in the ASIC language, giving you all the tools you need to play with any memory location in the PC.
If it's graphics you like, ASIC obliges you with a subset of BASIC's graphics features: COLOR, SCREEN PSET, and PRESET go hand in hand with the aforementioned POKE, PEEK, and VARPTR. SCREEN is a subset of the BASIC version but contains the essentials; I felt BLOAD and BSAVE were the only glaring omissions. The text-based CRSLIN, POS, and LOCATE round out the features you need to move characters around onscreen; in fact, the example program with ASIC is an excellent version of LIFE, the cellular automation game.
Perhaps my favorite extension is ZMODE, which returns 1 if the current video mode supports color and 0 if it's a monochrome card. This is important for games and other applications what write directly to video memory; since ASIC supports POKE, and PEEK, you can use ZMODE to locate the screen.
Oddly, there's no straightforward way to do this in other BASICs; you're forced to employ a machine language routine or, as so many programs do, ask the user what kind of screen is attached. Not only is this almost the zenith of tackiness (after all, shouldn't the program know more about itself?), but many users are unable to give the correct answer.
The manual is clearly written and weighs in at an impressive 63 pages. It's on disk in ready-to-print form and contains a Getting Started section, a tutorial, and reference for the integrated environment and the command line compiler.
The bulk of the reference section consists of a syntax chart and description for each keyword, function, and statement; but few entries contain examples. It's a common failing in first manuals and is hardly fatal, but it's an inconvenience.
Since there's only one sample program, you must resort to other book on BASIC to get the full picture.
If you're just getting your feet wet in BASIC and you need to distribute your programs to others, give ASIC a look. It's affordable, runs nicely on a floppy, and sports many features that full BASICs offer. It's hard to lose - and you might wind up with a brand new hobby.