EOPS&T_-_Computer_Software.pdf

(30364 KB) Pobierz
593875013 UNPDF
BASIC Programming Language
Thomas E. Kurtz
Dartmouth College
I. Brief Description
II. Early History of BASIC
III. Growth of BASIC
IV. Standardization and its Failure
V. The Microcomputer Revolution
VI. Present and Future
GLOSSARY
the rules of the language and with the purpose of car-
rying out a particular computing task.
Run Actual carrying out of the instructions of the pro-
gram by the computer.
Statement Instruction to the computer. In BASIC, state-
ments are virtually synonymous with lines and usually
begin with a keyword.
Subroutine Portion of a program, usually set off from the
rest of the program, that carries out some specific task.
Subroutines are usually invoked by special instructions,
such as GOSUB and RETURN in original BASIC, or
CALL in modern versions.
Variable Word in a program, usually different from a
keyword, that stands for a quantity, just as in ordinary
algebra.
BASIC Name of any of a large number of simple
programming languages that are similar and ulti-
mately derived from the original Dartmouth BASIC of
1964.
Keyword Word in a computer language that has a special
meaning. (Keywords in BASIC include, for instance,
LET , PRINT , FOR , NEXT , TO , and STEP .)
Language In computing, a programming language. Pro-
gramming languages like human languages, consist of
words and symbols together with grammatical rules
that govern how they can be put together.
Line Same as a line of text, beginning with a line number
in original BASIC.
Line number Integer (whole number) that begins each
line of a BASIC program and serves as a kind of
“serial number” for that line. Line numbers also serve
as “targets” for GOTO statements.
List A list of a program is a “printout” on the screen of
a computer or on a hard-copy printer, of the text of the
program (i.e., its lines).
Program Collection of statements, formed according to
BASIC (Beginner’s All-Purpose Simplified Instruction
Code) began as an interactive computer programming lan-
guage especially easy to learn. Invented in 1964, it now
exists in many widely different versions. Students learn-
ing programming for the first time may know BASIC as
the simple language found on most personal computers.
23
593875013.003.png 593875013.004.png
24
BASIC Programming Language
Others know BASIC as a development language on
personal computers and workstations. This article ex-
plores the history and development of BASIC, at least
some of the versions of BASIC, and explains why this
language has become so diverse and yet so popular.
100 INPUT X, Y
110LETZ=X+Y
120 PRINT Z
125 GOTO 100
130 END
I. BRIEF DESCRIPTION
This time, the result might look like this:
Nearly everyone who has heard about computers has heard
about the BASIC language. Many of these people can read
and write simple programs in BASIC. Note that, in 1964,
long before personal computers or display terminals, one
entered a program by typing (as now) and the computer
responded by typing back onto yellow paper (rather than
displaying results on a screen):
RUN
?3,4
7
? 1.23, 4.56
5.79
? 17.5, 5.3
12.2
?
100LETX=3
110LETY=4
120LETZ=X+Y
130 PRINT Z
140 END
The user continued in this fashion until all additional
problems had been “solved.” The user then stopped the
program by some method that varied from machine to
machine.
The above examples will be trivial to anyone who knows
BASIC but should be understandable even to someone
who has not used BASIC. It is not the purpose of this ar-
ticle, however, to teach the language through such sim-
ple examples. The purpose is rather to use these and
later examples to illustrate an important point: BASIC
is not just a single computer language; it is actually a
collection of many languages or dialects, perhaps hun-
dreds that have evolved since the mid-1960s. As a re-
sult, versions that run on different brands of computers
are different. It has even been the case that different mod-
els of the same brand have sported different versions of
BASIC.
For example, some versions of BASIC allowed the user
to omit the word LET , to omit the END statement, or to
employ either uppercase letters or lowercase letters inter-
changeably. For example, the first program above might
be allowed to appear on some computers as:
Almost anyone who has taken high school algebra will
understand what this program does and understand it well
enough to make changes in it. (When run, it prints the
number 7.)
BASIC was invented for an interactive environment
(time-sharing or personal computers). The user could start
and stop the program at will and could interact with the
running program. For instance, the INPUT statement in
the following program allowed the user to enter the num-
bers to be added after typing RUN (remember, all com-
mands had to be typed; there were no mouses or menus):
100 INPUT X, Y
110LETZ=X+Y
120 PRINT Z
130 END
After the user typed RUN , the program stopped (temporar-
ily), printed a question mark (?), and waited for the user
to respond. The user then typed two numbers, separated
by a comma, and followed by hitting the RETURN or
ENTER key. The program then commenced, calculated Z
(as the sum of the two numbers), and printed the answer.
The result might look like this on the yellow paper, or on
the screen of an early microcomputer:
100x=3
110y=4
120z=x+y
130 print z
One more important way in which versions of BASIC
developed is that some allow “structured programming”
(discussed later.) Recall an earlier example:
RUN
? 3.4
7
100 INPUT X, Y
110LETZ=X+Y
120 PRINT Z
125 GOTO 100
130 END
A user who wished to make several additions could
arrange for the program to continue indefinitely, as in:
593875013.005.png
BASIC Programming Language
25
One of the tenets of structured programming is that
GOTO statements (as in line 125 above), used carelessly,
are the cause of many programming errors. All modern
versions of BASIC allow the user to rewrite the above
program without using GOTO statements as:
undergraduate students.) The new language, BASIC, easy
to learn and easy to use, was an essential part of this effort.
BASIC was thus developed originally for a large multiple-
user, time-shared system and not for personal computers,
which did not appear widely until the early 1980s.
It has been asked why BASIC was invented. Couldn’tan
existing language have been used for the purpose? The an-
swer to the second question is no, which also answers the
first question. Other computer languages did exist in 1963,
although there were not nearly as many as there are today.
The principal ones were FORTRAN and Algol; most of
the others are long since forgotten. Some of the common
languages used today—C, C
100 DO
110 INPUT x, y
120 LETz=x+y
130 PRINT z
125 LOOP
130 END
, and Java—had not even
been conceived. FORTRAN and Algol were each consid-
ered briefly. These languages were designed for produc-
tion use on big machines or for scientific research, using
punched cards. But neither was suitable for use by begin-
ners, neither was particularly well suited for a time-shared
environment, and neither permitted speedy handling of
short programs. Kemeny and Kurtz had experimented with
other simple computer languages as early as 1956, but
with only modest success. So, in 1963, when they began
building a time-shared system for students, they quickly
realized that a new language had to be invented—BASIC.
++
The collection of lines starting with 100 DO and end-
ing with 125LOOP is known as a loop . The interior lines
of the loop are carried out repeatedly, as in the example
by using a GOTO statement. Notice, in addition, that the
program is written in mixed case (using both upper- and
lowercase letters), and the interior lines of the loop are in-
dented. All modern versions of BASIC allow these stylistic
improvements.
Eliminating the GOTO statement (line 125) removes the
need to reference line numbers in the program. The line
numbers themselves, no longer serving a useful purpose,
can now be eliminated to get:
DO
A. Design Goals
INPUT x, y
LETz=x+y
PRINT z
LOOP
END
The new language had to satisfy these properties:
1. It had to be easy to learn for all students.
2. It had to work well in a multiple-user, time-sharing
system.
3. It had to allow students to get answers quickly,
usually within 5 or 10 sec.
We could not have removed the line numbers from the
version that used a GOTO statement “ GOTO 100 ” be-
cause there would no longer be a line numbered 100 in
the program. Some earlier versions of BASIC allowed re-
moving some lines except for those used as GOTO targets,
in which case the line numbers became statement labels ,
a concept not present in the original BASIC.
In the years since BASIC was invented the importance of
time sharing has been overshadowed by the invention of
personal computers: Who needs to time-share a big ex-
pensive computer when one can have a big (in power)
but inexpensive computer on one’s desk top? For a long
time, no such dramatic improvement has been made on
the programming side. Thus, while the impact of time
sharing has been largely forgotten, the importance of
BASIC has increased. The ideals that forced the inven-
tion of BASIC—simplicity and ease of use—lead many
to choose BASIC today.
II. EARLY HISTORY OF BASIC
BASIC was invented at Dartmouth College in 1963–1964
by John G. Kemeny and Thomas E. Kurtz, both professors
of mathematics, assisted by a group of undergraduate stu-
dent programmers. Computers then were huge, slow, and
expensive; there were no personal computers. Their goal
was to bring easy and accessible computing to all students,
not just science or engineering students. The method they
chose called for developing a time-shared operating sys-
tem, which would allow many users simultaneously. (This
operating system was developed entirely by Dartmouth
B. The First Dartmouth BASIC
BASIC came into existence in the early morning of May 1,
1964, when two BASIC programs were run on the Dart-
mouth time-sharing system at the same time, both giving
the correct answer. That early version of BASIC offered
14 different statements:
593875013.006.png
26
BASIC Programming Language
LET PRINT END
READ DATA
GOTO IF-THEN
FOR NEXT
GOSUB RETURN
DIM DEF REM
150 IF F(N) > 100 THEN 999
160 GOSUB 500
170 PRINT F(N),
180 GOTO 150
500 REM SUBROUTINE TO COMPUTE
NEXT NUMBER
510LETN=N+1
520 LET F(N) = F(N-1)+F(N-2)
530 RETURN
999 END
LET , PRINT , and END were illustrated in the first ex-
ample program. READ and DATA were used to supply
data to the program other than through LET statements.
(It is a strange fact that the first version of BASIC did
not have the INPUT statement.) GOTO and IF-THEN
provided the ability to transfer to other locations in the
program, either unconditionally or conditionally on the
result of some comparison. FOR and NEXT were used
together and formed a loop. GOSUB and RETURN pro-
vided a crude subroutine capability. DIM allowed the user
to specify the size of a vector or matrix. DEF allowed the
user to define a new function (in addition to the functions
such as SQR , SIN , and COS that BASIC included au-
tomatically). REM allowed the user to add comments or
other explanatory information to programs.
We shall illustrate all 14 statement types in two short
programs. The first program uses eight of the statement
types and prints a table of the values of the common loga-
rithms (logarithms to the base 10) for a range of arguments
and a spacing given in a DATA statement:
The DIM statement (line 110) establishes a vector named
F having 20 components. Lines 120 and 130 establish
the first two numbers of the Fibonacci sequence. The
IF-THEN statement (line 150) checks to see if the most
recently computed Fibonacci number is greater than 100;
if it is, the program jumps to the END statement and stops.
If that is not the case, it computes the next number. Lines
150–180 are another example of a loop. The subroutine
(lines 500–530) contains the formula for computing the
next Fibonacci number. The subroutine is “called on” or
“invoked” by the GOSUB statement in line 160, which
refers to the subroutine by the line number of its first
statement. When the subroutine has finished its work, the
RETURN statement (line 530) “returns” control back
to the line following the line containing the GOSUB
statement.
Even in the earliest days, it was considered good form
to use REM statements to explain what the program did
and what each of the subroutines in the program did. The
use of indentation following the line number to display
the extent of the loop also began to appear around the
time BASIC was invented. The reason is that people, in
addition to computers, have to read computer programs;
remarks and indentation help. Two other stylistic features
were not common in 1964: lowercase letters (most ter-
minals did not even have them) and completely blank
lines.
100 REM PRINTS TABLE OF COMMON LOGS
110 READ A, B, S
120 DATA 1, 2, 0.1
130 DEF FNF(X) = LOG(X)/LOG(10)
140FORX=ATOBSTEP S
150 PRINT X, FNF(X)
160 NEXT X
170 END
(Common logarithms can be computed from “natural” log-
arithms with the formula shown in line 130. The program,
when run, prints a table of values of the common logarithm
for arguments 1, 1.1, 1.2, 1.3, etc., up to 2.)
The second program computes, stores in a vector, and
prints the Fibonacci numbers up to the first that exceeds
100. (The Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13
C. Major Design Decisions
We now consider the major design decisions made in 1964
and why they were made.
,....
The first two, 1 and 1, are given; each succeeding one is
obtained by adding the previous two.)
1. A Number is a Number is a Number; That is,
There is Only One Kind of Number in BASIC
100 REM FIBONACCI NUMBERS
110 DIM F(20)
120 LET F(1) = 1
130 LET F(2) = 1
140LETN=2
In 1964, as today, most machines could do arithmetic us-
ing several kinds of numbers. The two common kinds
were, and still are, integer numbers and floating-point
numbers. Integer numbers are simply whole numbers such
as 0, 17,
239, and 12345678. Floating-point numbers
593875013.001.png
BASIC Programming Language
27
can be thought of as numbers in “scientific” notation, as in
1.234
BASIC LETN=N+1
3. Although arithmetic using integer numbers
was usually faster, Dartmouth BASIC did all arithmetic
in floating point. While some programs might run more
slowly, life was made considerably easier for the beginner.
10
Three other design features in the original BASIC have
not withstood the test of time.
2. BASIC Should Read and Print Numbers
Without Requiring Special “Formats”
6. BASIC Should not Require Unnecessary
Declarations, Suchas Supplying
Dimensions for Arrays
FORTRAN, the most widely used language at that time,
used a complicated format control statement for all input
or output in the program, a requirement too complicated
for most students, particularly for those not taking science
or engineering.
The original BASIC allowed the use of single letters as
array names (arrays are also called lists and tables or, in
mathematical circles, vectors and matrices ). A single letter
with an attached subscript in parentheses represented an
array element. The following complete program, which
prints the squares of the whole numbers from 1–8, uses a
singly subscripted array (i.e., a list or vector):
3. One Should be Able to Create, Change, and
Run a BASIC Program from a Typewriter
100FORI=1TO8
110 LET X(I) = I*I
120 NEXT I
130FORI=1TO8
140 PRINT I, X(I)
150 NEXT I
160 END
Video screen terminals were not widely available in 1964.
The only alternative was the Teletype TM Model 33. It typed
in uppercase only and was very slow—10 characters per
second. The line numbers of a BASIC program allowed
users to change the program without retyping the entire
program; they needed merely to retype the corrected line,
including the line number.
4. BASIC Should have no Mysterious
Punctuation Rules; Thus, a Statement
and a Line are Synonymous
It was not necessary to include a DIM statement to estab-
lish that X stood for a vector, as in:
99 DIM X(8)
Other languages allowed statements to extend over sev-
eral lines and allowed several statements to appear on the
same line. Many used semicolons to separate statements,
regardless of the lines on which the statements appeared,
an unnecessarily complicated rule for beginners.
Such a DIM statement could be included, to be sure, but
if one were satisfied to work with elements X(1) through
X(10), the DIM statement would not be required. While
supplying sensible default values is still a cornerstone of
BASIC, default dimensioning of arrays has given way to
multi-character function names.
5. All BASIC Statements Should Commence,
After the Line Number, with a Keyword
7. BASIC Should be Blank Insensitive; That is,
a User Should be Able to Type in a Program
Without Regard to Blank Spaces
Most languages begin statements with a keyword. A com-
mon exception is the assignment statement, wherein vari-
ables receive the results of computations. Different lan-
guages treat the assignment statement in different ways:
This feature was intended to ease life for beginning typists.
The idea was that:
FORTRAN N = N+1
Algol N:=N+1;
100LETN=N+1
could be typed as
The FORTRAN method is confusing to the beginner; it
looks like an assertion that N is equal to N
+
1, which is
100LETN=N+1
symbol of the Algol method is supposed
to represent an arrow pointing to the left, but this may also
confuse most beginners. It was decided to use the keyword
LET to make the intention clear:
=
This decision meant that only simple variable names could
be used. The allowable variable names consisted of either
single letters or single letters followed by single digits.
×
nonsense. The :
593875013.002.png
Zgłoś jeśli naruszono regulamin