views:

938

answers:

14

When you write something in BASIC, you are required to use line numbers. Like:

10 PRINT "HOME"
20 PRINT "SWEET"
30 GOTO 10

But i wonder: who came up with the idea to use line numbers at all? It is such a nuisance, and left quite an "echo" in the developing (pun intended) world!

A: 

in Basic, if you didn't have a line number, how can you preform a

GOTO 10

that was a way to jump lines, a good way that was found ... more than 20 years ago!

today, the lines help us catching errors/exceptions because the debug engines are made to send us in the message that we got an exception on line xxx and we jump right away to it!

imagine a world without line numbers... how can a reporter be paid without the lines?

"Now that you know the novel, you have to write a summary with no more than 50 lines"

remember this? Even at the school we learn about line numbers!

if it wasn't invented, someone will already invented again so we could use it nicely :)

balexandre
You mean one with labels?
Peter Morris
labels are not the reason for basic line numbers, they are only a side effect such to say.
ypnos
@ypnos, you've got that backwards. Numbers as labels predated BASIC - in FORTRAN, for example, but in BASIC they took on the editing/insertion function.
Paul Tomblin
In FORTRAN you do not write the line number before every line of the program. That's what we are talking about here :)
ypnos
+25  A: 

The idea back then was that you could easily add code everywhere in your program by using the appropriate line number. That's why everybody uses line numbers 10, 20, 30.. so there is room left:

10 PRINT "HOME"
20 PRINT "SWEET"
30 GOTO 10
25 PRINT "HOME"

On the first interfaces BASIC was available for, there was no shiny editor, not even something like vi or emacs (or DOS edit, heh). You could only print out your program on the console and then you would add new lines or replace them, by giving the appropriate line number first. You could not navigate through the "file" (the program was kept in memory, although you could save a copy on disk) with the cursor like you are used to nowadays.

Therefore the line numbers weren't only needed as labels for the infamous GOTO, but indeed needed to tell the interpreter at what position in the program flow you are editing.

ypnos
That's actually how I learned to program - editing by retyping.
StuffMaster
sheepsimulator
I remember the fairly big problem of wanting to add a line between line 24 and 25, when there was no way of renumbering lines (on the Commodore PET).
e100
A: 

I like the robot church on Futurama, on the walls were written stuff like

10 SIN
20 GOTO HELL

On the Speccy you couldn't edit a line without the line number.

Peter Morris
+3  A: 

They originated in FORTRAN, from which BASIC was derived. However, in FORTRAN only lines referenced by other lines (like GOTO targets) needed numbers. In BASIC they had a secondary use, which was to allow editing of specific lines.

anon
In addition, FORTRAN line numbers were arbitrary, more like numeric labels than line numbers.
David Thornley
+16  A: 

It has a loong-loong history.

Line numbering actually comes from Dartmouth BASIC, which was the original version of the BASIC programming language and was the integral part of a so called Dartmouth Time Sharing System. That DTSS had a rudimentary IDE, which was nothing more than an interactive command line.

So every line typed inside this "IDE", and beginning with a line number, was added to the program, replacing any previously stored line with the same number; anything else was assumed to be a DTSS command and immediately executed.

Anton Gogolev
+5  A: 

Back in the day you didn't have a 2 dimensional editor like emacs or vi. All you had was the command line.

Your program was stored in memory and you would type in single line commands to edit single lines.

If you were a Unix god you could do it with ed or something, but for BASIC on a C-64, VIC-20, or TRS-80 you'd just overwrite the line.

So a session might look like:

$10 PRINT "Hellow World"
$20 GOTO 10
$10 PRINT "Hello World"

And now the program would work correctly.

Some older mainframes even had line terminals without a screen. Your whole session was printed on paper in ink!

Sean Cavanagh
A: 

I find them very helpful when pairing. I don't have to point at a line when my pair has the keyboard, I can just say, "on line 74, shouldn't that really be getMoreBeer()?"

Don Branson
I think the question was about languages where you had to type in the line numbers yourself. I agree line numbers that are displayed automatically by the editor are very useful .
Mendelt
yes, you're right. It seemed that there was perhaps some sentiment towards getting rid of them, but some still find them useful, so I thought I'd mention that.
Don Branson
+2  A: 

I'd guess it comes from assembler, where each instruction has an address which may be jumped to by another instruction.

Additionally, the first computers didn't have much memory, and storing a line number only takes two bytes (if done properly). Writing a lable takes more memory, first in the locaten, where that lable is defined, then in any jump command.

Finally in the good old days there weren't any fancy editory. The only "editor" was a simple command line interface, which threated everything starting with a number being part of a program and everything else as commands to be executed immediatelly. Most prominent example should be the Commodore 64.

Newer dialects of Basic don't have the need for line number any loger.

bothie
The other advantage of sequential line numbers is that you don't have to do a first pass to pick up the labels and their locations - you can just interpret the program and run it in the same pass.
Paul Tomblin
+14  A: 

Before there was such a thing as a VDT (video display terminal), we old-timers programmed on punch cards. Punch cards reserved columns 72-80 for sequence numbers - if you dropped your card deck and they all got out of order, you could put the deck in a collater that would order the cards based on those sequence numbers. In many ways, the BASIC line numbers were similar to those sequence numbers.

Another advantage in the BASIC world is that in the old days BASIC was interpreted as it was run. Using labels rather than sequential line numbers for branches would require a first pass to pick up all the labels and their locations, where as if you use line numbers the interpreter knows whether it needs to start scanning forwards or backwards for the destination.

Paul Tomblin
This is the only right answer!
Christopher W. Allen-Poole
Sort of a combination of the end-of-the-card sequence numbers and the beginning-of-the-card line labels. Easy to see how it looked like a win.
David Thornley
Actually it's a complete red herring. Basic didn't exist until interactive teletypes were commonplace - punch cards are not part of the answer to this question.
U62
@U62 - I was explaining where the concept of sequence numbers came from, not where BASIC came from.
Paul Tomblin
Even though it's irrelevant? GJ
U62
It's not irrelevant, it's history. Do you consider your parents irrelevant because they're not you?
Paul Tomblin
@U62 - The answer is still relevant because the convention of using sequence numbers was carried forward. It's ridiculous to suppose that programming conventions still common in the 70s had no influence on what was adopted in the 80s. Progress takes time.
Parappa
A: 

The original editor for DOS was a wonderful utility called edlin. You could only edit a single line. To make life even more interesting in many versions of BASIC you could type lines out of order, line 10, 20, 30, 25, 5, The execution would be by line line number not by the order of appearance.

Jim C
A: 

Not all versions of BASIC required line numbers. QBasic, for instance, supported labels. You could then jump to those with GOTO (ignoring Dijkstra's "Go To Statement Considered Harmful," for the moment).

R. Bemrose
QBasic was one of the first versions of BASIC not to require line numbers. It came with a program to remove unneeded line numbers from GW-BASIC code.
dan04
A: 

The answer is already above. Paul Tomblin wrote it (with a caveat to zabzonk).

Actually, I would argue that any answer which does not mention "punch cards" is incomplete, if it mentions neither punch cards nor FORTRAN, it is wrong. I can say that this is definitively right because my parents both used punch cards on a regular basis (they started with FORTRAN 66 and 77), then migrated to Basic and COBOL in the 80's.

Christopher W. Allen-Poole
+1  A: 

Back in the fifties, when high programming languages were in their early beginnings, there were no terminals, no editors, no monitors (yes, no monitors), just card punchers and readers (for writing and reading the contents of cards into memory of a computer) and printers (for printing results, naturally). Later, tape was introduced, but that's another story.

Each punch card had its own number. There were several reasons for that; from purely keeping them in order, to determining the sequence of execution. Each card was one line of code (in today's terms). Since, at that time, there were no constructs like if..then..else, or whatever variant of the like, the sequence of execution had to be determined somehow. So GOTO statements were introduced. They were the basis of loops. The term "spaghetti code" comes from that time period also, since badly written code was relatively hard to follow, like spaghetti on a plate :)

ldigas
+1  A: 

The "Who?" would be the inventors, Kemeney and Kurtz.

After reading the replies, I checked the Wikipedia entry for "Dartmouth BASIC", and was surprised to learn

The first compiler was produced before the time-sharing system was ready. Known as CardBASIC, it was intended for the standard card-reader based batch processing system.

So, it looks like Paul Tomblin "gets the square".

gbarry
And in high school, we had a "modem" that let us dial into Dartmouth's computer, and experience this wonder first hand.
gbarry