Encyclopedia > BASIC

  Article Content

BASIC programming language

Redirected from BASIC

BASIC is a family of high-level programming languages. Originally devised as a teaching tool, it became widespread on home microcomputers in the 1980s, and remains popular to this day in a handful of heavily altered dialects.

The name is an acronym for Beginner's All-purpose Symbolic Instruction Code1, although BASIC's name was invented to result in a nice acronym. The acronym is tied to the name of an unpublished paper by Thomas Kurtz and has no relation to C. K. Ogden[?]'s series titled "Basic English".

Some critics have called the language Bill's Attempt to Seize Industry Control in response to Microsoft's policies with respect to BASIC interpreters included with home computers.

Table of contents

History

Prior to the mid-1960s, computers were terribly expensive tools that were used only for special-purpose task, running a single "job" at a time. During the 1960s, however, computers started to drop in price to the point where even small companies could afford them, and the speed increased to the point where they often sat idle because there weren't enough jobs for them.

Programming languages of the era tended to be designed, like the machines they ran on, for specific purposes such a scientific formula processing. Since single-job machines were expensive, they also tended to consider execution speed to be the most important feature of all. In general they were hard to use, and tended to be somewhat "ugly".

It was at this time that the concept of time-sharing systems started to become popular. In such a system the processing time of the main computer was "sliced up" and each user was given a small amount in sequence. The machines were fast enough that most users would be fooled into thinking that they had a single fast machine to themselves. In theory timesharing reduced the cost of computing tremendously, as a single machine could be shared among, in theory at least, hundreds of users.

The original BASIC language was invented in 1964 by John George Kemeny (1926-93) and Thomas Eugene Kurtz (1928-) at Dartmouth College. BASIC was designed to allow students to write programs using time-sharing computer terminals. BASIC intended to address the complexity issues of older languages with a new language designed specifically for the new class of users the time-sharing systems allowed – that is, a "simpler" user who was not as interested in speed as in simply being able to use the machine. The designers of the language also wanted it to remain in the public domain, which helped it to spread.

The eight design principles of BASIC were:

  1. Be easy for beginners to use
  2. Be a general-purpose language
  3. Allow advanced features to be added for experts (while keeping the language simple for beginners)
  4. Be interactive
  5. Provide clear and friendly error messages
  6. Respond fast for small programs
  7. Not require an understanding of computer hardware
  8. Shield the user from the operating system

The language was based partly on FORTRAN II and partly on Algol 60, with additions to make it suitable for timesharing and matrix arithmetic, BASIC was first implemented on the GE-2651 mainframe which 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 to deride BASIC as being too slow and too simple2. Such elitism is a recurring theme in the computer industry.

BASIC nevertheless spread to a number of machines, and became fairly popular on newer minicomputers like the DEC PDP series and the Data General Nova. In these instances the language tended to be implemented as an interpreter instead of a compiler, or alternately, both were supplied.

However it was the introduction of the Altair 8800 computer in 1975 that truly spread BASIC. Most programming languages were too large to fit in the small memory on these machines, and with the slow disk speeds and lack of a suitable editor, a small language like BASIC was tailor made for such use. One of the first to appear on this machine was Tiny BASIC, a simple version originally written by Dr. Li-Chen Wang, and then ported onto the Altair by Dennis Allison at the request of Bob Albrecht (who later founded DDJ). The Tiny BASIC design and the full source code was published 1976 in Dr. Dobb's journal.

In 1977 Microsoft (then two people) released Altair BASIC. Versions then started appearing on other platforms under licence, and millions of copies were soon in use when it became one of the standard languages on the Apple II. By 1979 Microsoft was in talks with several microcomputer vendors, including IBM, to licence a BASIC interpreter for their computers. A version was included on the IBM PC's BIOS ROM chip and was loaded on start-up.

As newer companies attempted to follow the success of the Apple II, and thus created the home computer revolution, BASIC became a standard feature of them all. Soon there were many millions of machines running BASIC around the world, likely a far greater number than all of the users of all other languages put together.

Many programs, especially those on the Apple II and IBM PC, depended on the presence of Microsoft's BASIC interpreter and would not run without it; thus, Microsoft used the copyright license on the BASIC interpreters to gain leverage in negotiations with the computer vendors.

Newer and more powerful versions were created in this time period. Microsoft sold several versions of BASIC for DOS including BASICA, GW-BASIC, Quick BASIC. Borland published Turbo Basic 1.0 in 1985. Successor versions are still sold under the name of PowerBasic by another company. Other languages used the widely-understood BASIC syntax as the basis for otherwise completely different systems, GRASS being one example.

However by the mid-1980s newer computers were far more complex and included features (such as graphical user interfaces) that made BASIC less and less suitable for programming them. At the same time computers were progressing from "toys" to tools used primarily for running applications written by others, and programming as a whole became less important for the growing majority of uses. BASIC then started to fade, although numerous versions were still available.

BASIC's fortunes were reversed once again with the introduction of Visual Basic from Microsoft. Although it is somewhat difficult to consider this language to be BASIC (despite its using many familiar BASIC keywords) it has gone on to become one of the most used languages on the Windows platform, and is said to represent some 70 to 80% of all commercial development. Visual Basic for Applications was added to Microsoft Excel 5.0 in 1993 and to the rest of the Microsoft Office product line in 1997. Windows 98 included a VBScript interpreter. The most recent version is called VB .NET. OpenOffice as well includes a Basic variant although not as powerful as its MSOffice counterpart.

Syntax

A very minimal BASIC syntax only needs the LET, PRINT, IF and GOTO commands. An interpreter which executes programs with this minimal syntax doesn't 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. A BASIC interpreter with these features requires the code to have line numbers.

Modern BASIC dialects have abandoned line numbers, and sport the full wealth of the control and data declaration constructs as known in other languages like Pascal or Modula-2.

Recent variants like Visual Basic introduced object-orientation and in the last version even with inheritance. Memory management is easier because of an included garbage collector.

The wealth of variants shows that the language is an "organic" language and that it is rather a subculture which deals with computer programming than a fixed set of syntax rules. The same applies to other "old" computer languages like COBOL and FORTRAN as well, however the BASIC movement is by far the largest.

Procedures and Flow Control BASIC doesn't have a standard external library like other languages such as C. Instead, the interpreter or 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 and output, graphics and file manipulation.

Some BASIC dialects do not allow programmers to write their own procedures. Programmers must instead write their programs with large numbers of GOTO statements for branching. This can result in very confusing source called commonly referred to as spaghetti code. GOSUB[?] statements branch to simple kinds of subroutines without parameters and without local variables. Most versions of BASIC such as Microsoft QuickBASIC have added support for full subroutines and functions. This is another area where BASIC varies from other languages. BASIC makes a distinction between a procedure which does not return a value (called a subroutine or SUB) and a procedure which does (called a function). Many other languages make no distinction and consider everything a function (with some returning a "void" value).

While functions in the larger sense of subroutines returning values were a latecomer to BASIC dialects, many early systems supported the definition of one-line mathematical functions with DEF FN. The original Dartmouth BASIC also supported Algol-like functions and subroutines from an early date.

BASIC is well known for its string manipulation functions. Already early dialects had a set of fundamental functions (LEFT$, MID$, RIGHT$) to deal with strings easily. As strings are often used in everday applications this was a considerable advantage over other languages at the time of its introduction.

Data types

The original Dartmouth BASIC supported only numeric and string data types. There was no integer type. All numeric variables were floating point. Strings were dynamic length. Arrays of both numbers and strings were supported, as well as matrices (two dimensional arrays).

Every modern BASIC dialect at least has the integer and string data types. Data types are usually distinguished with a following character; string identifiers end in $, whereas integers do not. In some dialects, variables must be declared (with DIM) on first usage; other dialects do not require this, but have the option to enforce it -- typically using a directive such as Option Explicit. Many dialects also support additional types, such as 16 and 32-bit integers and floating-point numbers. Additionally some allow the definition of user-defined types, similar to Pascal records or C structs.

Most BASIC dialects beyond the most primitive also support arrays of integers or other types. In some, arrays must be preallocated before they can be used (with the DIM statement). Support for two and higher-dimensional arrays, as well as arrays of non-integer types, will more than likely be included.

 DIM myIntArray(100) AS INTEGER
 DIM myNameList(50) AS STRING
Depending on the dialect of BASIC and on use of the Option Base statement, values can range from myIntArray(0) to myIntArr(100), from myIntArr(1) to myIntArr(100) or from myIntArray(LowInteger) to myIntArray(HighInteger).

Comparison operators

 = equal

 < less than

 > greater than

 <= less than or equal to

 >= greater or equal to

 <> not equal to

Availability and dialect variants

BASIC is available for nearly every microprocessor platform made. One free interpreted version that is compliant with standards and highly cross-platform is ByWater BASIC. The interpreter is written in C and comes under a GNU license. It doesn't include an builder for creating graphical user interfaces (GUIs).

A free version which includes a GUI builder, is similar to Visual Basic and runs on Windows and Linux is Phoenix Object Basic.

The best known compiled versions are Microsoft's Quick BASIC product line and QBASIC, (a version which does not generate standalone programs.) Some versions of Visual Basic are also compiled, although Microsoft has altered Visual Basic into a language minimally compatible with even early versions of Dartmouth BASIC.

Other versions include PowerBASIC's PowerBASIC[?], as well as True BASIC's True BASIC, which is compliant with the latest official standards for BASIC. (True BASIC Inc. was founded by the original creators of Dartmouth BASIC.)

REALbasic is a variant available for the Apple Macintosh which also generates executables for Microsoft Windows.

A variant of a simple Basic dialect for the parrot Virtual machine shows how a Basic interpreter is implemented in an assembly like language.

PureBasic is a variant with a simple syntax but which produces fast and tiny executable files for Windows and Linux. It can as well compile in-line assembly instructions.

SmallBasic is a dialect which runs on many platforms (Win32, DOS, Linux and PalmOS) and comes unter a GNU license.

Examples

Sample 1: Unstructured original BASIC (Applesoft BASIC)

 10 INPUT "What is your name"; A$
 20 PRINT "Hello "; A$
 30 INPUT "How many stars do you want"; S
 40 FOR I = 1 TO S
 50 S$ = S$ + "*"
 55 NEXT I
 60 PRINT S$
 70 INPUT "Do you want more stars"; Q$
 80 IF LEN(Q$) = 0 GOTO 70
 90 Q$ = LEFT$(Q$, 1)
 100 IF (Q$ = "Y") OR (Q$ = "y") THEN GOTO 30
 110 PRINT "Goodbye ";
 120 FOR I = 1 TO 200
 130 PRINT A$; " ";
 140 NEXT I
 150 PRINT

Sample 2: Modern Structured BASIC

 INPUT "What is your name"; UserName$
 PRINT "Hello "; UserName$
 DO 
   INPUT "How many stars do you want"; NumStars

   Stars$ = ""
   Stars$ = REPEAT$("*", NumStars) '<-ANSI BASIC
   'Stars$ = STRING$(NumStars, "*") '<-MS BASIC
   PRINT Stars$
   DO
     INPUT "Do you want more stars"; Answer$
   LOOP UNTIL Answer$ <> ""
 LOOP WHILE UCASE$(LEFT$(Answer$, 1)) = "Y"
 PRINT "Goodbye ";
 FOR A = 1 TO 200
   PRINT UserName$; " ";
 NEXT A
 PRINT

Dialects

Standards

  • ANSI Standard for Minimal BASIC (ANSI X3.60-1978 "FOR MINIMAL BASIC")
  • ISO Standard for Minimal BASIC (ISO/IEC 6373:1984 "DATA PROCESSING - PROGRAMMING LANGUAGES - MINIMAL BASIC")
  • ANSI Standard for Full BASIC (ANSI X3.113-1987 "PROGRAMMING LANGUAGES FULL BASIC") $79 USD
  • ISO Standard for Full BASIC (ISO/IEC 10279:1991 "INFORMATION TECHNOLOGY - PROGRAMMING LANGUAGES - FULL BASIC") $53 USD
  • ANSI Addendum Defining Modules (X3.113 INTERPRETATIONS-1992 "BASIC TECHNICAL INFORMATION BULLETIN # 1 INTERPRETATIONS OF ANSI 03.113-1987")
  • ISO Addendum Defining Modules (ISO/IEC 10279:1991/ Amd 1:1994 "MODULES AND SINGLE CHARACTER INPUT ENHANCEMENT")

External links

References and Notes

1Per correspondence with Thomas E. Kurtz.

Based on an article originally written for Nupedia (http://www.nupedia.com/) by Peter Fedorow fedorowp@yahoo.com

2In a 1968 article Edsger Dijkstra considered programming languages using GOTO statements for program structuring purposes, harmful for the productivity of the programmer and the quality of the resulting code(Communications of the ACM Volume 11, 147-148. 1968, reprinted here (http://www.acm.org/classics/oct95/)). This article does not mention any particular programming language. It merely states that the overuse of GOTO is a Bad Thing and gives the technical reasons why this should be so.

In a 1975 tongue-in-cheek article, published in Sigplan Notices Volume 17 No. 5, How do We Tell Truths that Might Hurt (reprinted here (http://www.cs.virginia.edu/~evans/cs655/readings/ewd498)), he gives a list of uncomfortable truths, including his opinion of several programming languages of the time, such as BASIC. It appears that many people confuse the two articles and conclude that Dijkstra particularly hated BASIC as a result of its GOTO statement. However BASIC receives no worse treatment than PL/I, COBOL or APL in his articles.

The BASIC Handbook, 2nd Edition by David A. Lien, Compusoft Publishing, 1981 documents dialect variation for over 250 versions of BASIC.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Isopleth

... pressure: isobar. temperature: isotherm. dew point: isodrosotherm. humidity: isohume. wind speed: isotach. wind direction: isogon. liquid ...