Before the mid-1960s, computers were highly expensive tools used only for special-purpose tasks, which ran a single "job" at a time. During the 1960s, however, computer prices started to drop to where even small companies could afford them. Their speed increased to the point they often sat idle, without jobs to run.
Programmers designed programming languages mostly for specific purposes such as scientific formula processing. Since single-job machines were expensive, the tendency was to consider execution speed the most important feature of all. They were hard to use, and tended toward certain "ugliness."
It was at this time that the timesharing system idea started to become popular. In such a system the processing time of the main computer is "sliced up" between the computer and each user. The machines were fast enough for most users to feel they had a single machine all to themselves. In theory, timesharing reduced the cost of computing tremendously, because hundreds of users could share a single machine.
The original BASIC language is a programming language created in 1964 by John Kemeny (1926-93) and Thomas Kurtz (1928-) at Dartmouth College. A team of Dartmouth students developed BASIC under their direction. In the following years, as other dialects of BASIC appeared, Kemeny and Kurtz' original BASIC dialect became known as Dartmouth BASIC.
The purpose of BASIC was to allow students to write programs using timesharing computer terminals. Its intention was to address the complexity issues of older languages with a new language designed specifically for the new class of users the timesharing systems allowed - that is, a "simpler" user who was not as interested in speed as in simply use the machine.
The eight design principles of BASIC were:
- easy to use
- general-purpose language
- advanced features for experts while keeping it simple for beginners
- clear error messages
- fast for small programs
- no need to understand computer hardware
- no interaction with the operating system
The language based partly on FORTRAN II and partly on ALGOL 60, with additions to make it suitable for timesharing and, later, text processing and matrix arithmetic. BASIC was first implemented on the GE-265' mainframe that supported multiple terminals. Contrary to popular belief, it was a compiled language at the time of its introduction. Almost immediately after its release, computer professionals started deriding BASIC as too slow and too simple; such elitism is a recurring theme in the computer industry.
Nevertheless, the designers of the language decided that it should remain in the public domain to help it spread. They also made it available to high schools in the Dartmouth area and spent a considerable amount of effort in promoting the language. As a result knowledge of BASIC became relatively widespread for a computer language. Several manufacturers implemented BASIC, and became fairly popular on newer minicomputers like the DEC PDP series and the Data General Nova. In these instances the language was an interpreter instead of a compiler, or alternately, both.
However, it was the introduction of the Altair 8800 microcomputer in 1975 that truly spread BASIC. Most programming languages were too large to fit in the small memory most users could afford on these machines. With the slow storage on paper tape or later audio cassette tape and the lack of suitable text editors, a small language like BASIC was a good fit. BASIC also had the advantage that the young designers who took an interest in microcomputers at the time knew it fairly well. One of the first languages to appear for this machine was Tiny BASIC, a simple BASIC implementation originally written by Dr. Li-Chen Wang, and then ported onto the Altair at the request of Bob Albrecht (who later founded Dr. Dobb's Journal). DDJ published the Tiny BASIC design and the full source code in 1976.
In 1977, Microsoft (then only two people - Bill Gates and Paul Allen) released Altair BASIC, coauthored by Gates, Allen and Monte Davidoff. Versions then started appearing on other platforms under license, and millions of copies and variants were soon in use; it became a standard language on the Apple II. By 1979, Microsoft was talking with several microcomputer vendors, including IBM, about licensing a BASIC interpreter for their computers. The IBM PC ROM chips and PCs without hard disks automatically booted into an included version of BASIC.
Newer companies attempted to follow the successes of Altair, IMSAI, North Star and Apple, thus creating the home computer revolution; meanwhile, BASIC became a standard feature of all but a very few home computers. Most came with a BASIC interpreter in ROM, a feature pioneered by the Commodore PET in 1977. Soon there were many millions of machines running BASIC around the world, likely a far greater number than all the users of all other languages put together. Many programs, especially on the Apple II and IBM PC, depended on the presence of Microsoft's BASIC interpreter and would not run without it; in this way, Microsoft used its copyright licenses on its BASIC interpreter to gain leverage in negotiations with the computer vendors.
Software companies created many newer BASIC versions during this period. Microsoft sold several versions of BASIC for MSDOS/PCDOS including BASICA, GW-Basic (a BASICA-compatible version that did not need IBM's ROM) and Quick BASIC. Turbo Pascal-publisher Borland published Turbo BASIC 1.0 in 1985. Another company still sells successor versions under the name PowerBASIC. Various extensions of home computer BASIC appeared, typically with graphics, sound, DOS commands, and facilities for structured programming. Other languages used the widely-known BASIC syntax as the basis for otherwise completely different systems (GRASS being one example).
However, by the end of the 1980s newer computers were far more complex and included features (such as graphical user interfaces) that made BASIC less suitable for programming. Also, computers had progressed from a hobbyist interest to tools used primarily for applications written by others. Programming as a whole became less important for the growing majority of users. BASIC started to fade, though many versions remained available.
BASIC reversed in fortune again with the introduction of Visual Basic from Microsoft. Though it is somewhat difficult to consider this language to be BASIC (despite its many familiar BASIC keywords). It became a popular language on the Windows platform, representing some 70 to 80% of all commercial development. Microsoft added Visual Basic for Applications (VBA) to Excel 5.0 in 1993 and to the rest of its Office suite in 1997. Windows 98 included a VBScript interpreter. The most recent version of Visual Basic is VB.NET. The competing OpenOffice suite includes a BASIC variant reportedly less powerful than its Microsoft counterpart.
Basic statements end with line endings unless there is a line continuation character. A very small BASIC program only needs the LET, PRINT, IF and GOTO commands. An interpreter that executes programs with this small syntax does not need a stack. Some early microcomputer implementations were this simple. If one adds a stack, nested FOR-loops and the GOSUB command can be added. An interpreter with these features requires the BASIC code to have line numbers.
Line numbers were a very distinctive aspect of classic home computer BASIC. Alas, line numbers have the disadvantage of requiring the programmer to guess how many lines a given program part will take. This need is most often met by habitually incrementing successive line numbers by a regular interval, say 10. This naturally leads to problems when later-added code exceeds the number-space available between the original lines. To alleviate this problem with early BASIC interpreters, expert users soon wrote their own utility programs for renumbering their programs after initial entry. Some BASIC interpreters later appeared with a built-in RENUMBER command, thus eliminating the most pressing problem with line numbers.
Modern BASIC dialects have abandoned line numbers, and support most (or all) of the structured control and data declaration constructs known in other languages like C and Pascal (note also that some advanced versions of line number-based home computer BASICs incorporated such constructs as these to good effect):
do - loop - while - until - exit on x goto / gosub (switch & case)
Recent variants such as Visual Basic have introduced object-oriented features, and even inheritance in the latest version. Memory management is easier than in many other procedural programming languages because of the commonly included garbage collector (presumably for which, however, one pays a runtime performance penalty).
This wealth of variants shows that the language is an "organic" one. It is a subculture dealing with computer programming rather than as a fixed set of syntactic rules. The same applies as well to other "old" computer languages like COBOL and FORTRAN, although the BASIC movement is by far the largest. An explanation of this is the large number of IT professionals who cut their teeth on BASIC programming during the home computer era in the 1980s.
BASIC does not have a standard external library like other languages such as the C language. Instead, the interpreter (or the compiler) contains an extensive built-in library of intrinsic procedures. These procedures include most of the tools a programmer needs to learn programming and write simple applications, including functions for math, strings, console input/output, graphics and file manipulation.
Some BASIC dialects do not allow programmers to write their own procedures. Programmers must instead write their programs with many GOTO statements for branching. This can result in very confusing source code, commonly called spaghetti code. GOSUB statements branch to simple kinds of subroutines without parameters or local variables. Most modern versions of BASIC such as Microsoft QuickBASIC have added support for full subroutines and functions. This is another area where BASIC differs from many other programming languages. BASIC, like Pascal, makes a distinction between a procedure that does not return a value (called a subroutine) and a procedure that does (called a function). Many other languages (notably C) make no distinction and consider everything a function (with some returning a void value).
Functions in the larger sense of subroutines returning values were latecomers to BASIC dialects. Many early systems supported the definition of one-line mathematical functions by DEF FN ("DEFine FunctioN"). The original Dartmouth BASIC also supported Algol-like functions and subroutines from an early date.
BASIC is notable for good string manipulation functions. Early dialects already had a set of fundamental functions (LEFT$, MID$, RIGHT$) to deal with strings easily. Because strings are often used in everyday applications this was a considerable advantage over other languages at the time of its introduction.
The original Dartmouth BASIC supported only numeric and string data types. There was no integer type. All numeric variables were floating point types. Strings were dynamic in length. Arrays had one and two dimensions (matrices) and contained both numbers and strings.
Every modern BASIC dialect at least has the integer and string data types. A suffix character usually distinguishes data types; string identifiers end in $, whereas integers do not. In some dialects, variables declared (with DIM) are necessary on their first usage; other dialects do not require it, but can optionally enforce typically using a directive such as Option Explicit. Many dialects also support such additional types as 16- and 32-bit integers and floating-point numbers. Additionally, some allow user-defined types similar to Pascal records or C structures.
Most BASIC dialects beyond the most primitive also support arrays of integers or other types. In some, array preallocation (with the DIM statement) is necessary before use. Support for two and higher-dimensional arrays, and arrays of non integer types, is common.
DIM myIntArray (100) AS INTEGER DIM myNameList (50) AS STRINGDepending on the dialect of BASIC and use of the Option Base statement, values can range from:
myIntArray(0) to myIntArr(100) myIntArr(1) to myIntArr(100) myIntArray(Low Integer) to myIntArray(High Integer)However, in Visual Basic.NET, all arrays are zero-indexed, meaning the first element has an index of 0, as in the first of the above examples.
= equal < less than > greater than <= less than or equal <> not equal >= greater than or equal AND logical conjunction OR logical disjunction NOT logical negation
(Note that there is no lexical distinction between the equality operator and the assignment operator in BASIC.)
10 INPUT "First number"; A
20 INPUT "Second number"; B
30 PRINT "The sum of the numbers is";A + B
40 IF A + B = 10 THEN GOTO 60
50 GOTO 10
DO INPUT "First number"; A INPUT "Second number"; B PRINT "The sum of the numbers is";A + B IF A + B = 10 THEN EXIT DO LOOP END