Many early implementations of BASIC had line numbers. I’ve seen many questions posted on FaceBook and other places that typically say, “Why on earth does BASIC have line numbers?” I’ll try to answer that question today.
In the very early days of time sharing systems, the only user interface to computers was through hard copy terminals. A typical example would be an ASR-33 Teletype machine. These machines had a roll of paper, and the user commands would be printed on the paper, and the computer’s response was also be printed on the paper.
The Unix ed command is very typical of the types of text editors that were available in the ‘60s. Here’s an example of an interaction I recently had with ed. Believe it or not ed is still included with Linux.
ed <-- Me asking to start ed
a <-- Add text command
hello |
this |
is |
a |
test |
. <-- Me saying end text
1,$p <-- I ask for print back
hello <-- Computer
this |
is |
a |
test |
2i <-- I ask to enter text before line 2
hi <-- Me entering text
. <-- Me saying end of text
1,$p <-- I ask for print back
hello <-- Computer
hi |
this |
is |
a |
test |
2i <- I ask to enter text before line 2
bye |
. <- Me saying end of text
1,$p <- Me saying print back
hello <- Computer
bye |
hi |
this |
is |
a |
test |
w gary.txt <-- Me asking to write file
28 <-- computer says 28 bytes
q <-- Me asking to quit
gary@Gary:~$ cat gary.txt <-- Linux prompt. Print back
hello <- Computer
bye |
hi |
this |
is |
a |
test |
gary@Gary:~$ <- Computer prompt
Needless to say, this is pretty awful. You wouldn’t ask a novice computer user to do this. The brilliance of Kemeny and Kurtz was their recognition that there was a much better way. With the use of line numbers the above interaction could look like this:
10 hello <-- Me
20 this
30 is
40 a
50 test
list
10 hello <-- Computer
20 this
30 is
40 a
50 test
15 hi <-- Me
list
10 hello <-- Computer
15 hi
20 this
30 is
40 a
50 test
12 bye <-- Me
list
10 hello <-- Computer
12 bye
15 hi
20 this
30 is
40 a
50 test
save gary.txt <-- Me
I think you’d agree that the second scenario is much easier to follow.
One other consideration, if we are developing a new simple programming language we need to have some form of control flow. Aha!! Let’s use the line numbers. Remember this is 1964 and structured programming had not been invented. FORTRAN also used numbers as targets for GO TOs, so we are in good company.
So writing a program to count from one to 10, might look like this: (ignoring FOR-NEXT for now.)
10 let i = 1
20 print i
30 let i = i + 1
40 if i <= 10 then go to 20
50 end
Now, let’s say it is the mid-seventies. People like Bill Gates, and Steve Wozniak are learning how to program. What are they familiar with? A dialect of BASIC on Teletype machines with line numbers. It’s just natural for them to follow this pattern.
Are line numbers necessary when displays arrive? No, not really, but there is a huge amount of momentum built for line numbers. I believe it wasn’t until the early ‘90s until you saw BASICs without line numbers. Microsoft’s QBasic is one I remember. If you know of others please put them below in the comments below.
The first published (!) BASIC dialect that came without line numbers was the Amiga BASIC in 1985, as far as I know - and this is a Microsoft-BASIC. One year earlier some Apple engineers worked on an "Mac BASIC" which did not use line numbers either - but was never published since the Apple company had a contract with Microsoft to produce their sole BASIC for Macs.
Many professions, especially any that deal with ancient texts use line numbers, or paragraph numbers. The Bible uses verse numbers, the Lutheran Confessions of the 16th century, uses paragraph numbers, and many official referendums and memorials proposed using Roberts Rules of Order, will use line numbers for ease of floor amendments during a meeting, convention, or convocation.