Why did we bother with line numbers at all?

10,546

Solution 1

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.

Solution 2

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.

Solution 3

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 card sorter 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.

Solution 4

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!

Solution 5

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".

Share:
10,546
oɔɯǝɹ
Author by

oɔɯǝɹ

Developer! Developer! Developer!

Updated on June 05, 2022

Comments

  • oɔɯǝɹ
    oɔɯǝɹ almost 2 years

    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!

  • ypnos
    ypnos about 15 years
    labels are not the reason for basic line numbers, they are only a side effect such to say.
  • Paul Tomblin
    Paul Tomblin about 15 years
    @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
    Paul Tomblin about 15 years
    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.
  • Mendelt
    Mendelt about 15 years
    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 .
  • ypnos
    ypnos about 15 years
    In FORTRAN you do not write the line number before every line of the program. That's what we are talking about here :)
  • cwallenpoole
    cwallenpoole about 15 years
    This is the only right answer!
  • David Thornley
    David Thornley about 15 years
    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.
  • Paul Tomblin
    Paul Tomblin about 15 years
    @U62 - I was explaining where the concept of sequence numbers came from, not where BASIC came from.
  • J. Polfer
    J. Polfer about 15 years
    This brings back memories of writing GW-BASIC apps on my parents AT&T PC6300...
  • U62
    U62 about 15 years
    Even though it's irrelevant? GJ
  • Paul Tomblin
    Paul Tomblin about 15 years
    It's not irrelevant, it's history. Do you consider your parents irrelevant because they're not you?
  • gbarry
    gbarry about 15 years
    And in high school, we had a "modem" that let us dial into Dartmouth's computer, and experience this wonder first hand.
  • e100
    e100 over 14 years
    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).
  • Parappa
    Parappa about 14 years
    @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.
  • dan04
    dan04 about 14 years
    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.
  • aramis
    aramis almost 12 years
    BASIC was around in the 1970's... and there were punchcard fed basic implementations. As a kid, I earned my D&D buying money punching cards for CS majors, including some BASIC.
  • Swanny
    Swanny over 11 years
    Yep I agree. It definately was a tie over from the mentality of punch cards. Also since most early home computers had a line numbered basic built in (Apple, Commodore, etc) it became very common. Interestingly enough, this also allowed you to enter your programs non-sequentially, which helped with their limited editting capabilites. One of the first things I wrote in BASIC was a text edit program. But as soon as I got my hand on a Vax with it's Extended BASIC, I was so happy to never see a line number again.
  • Phil Perry
    Phil Perry almost 10 years
    And right about now (early 2014) is the 50th anniversary of BASIC!
  • Jules
    Jules about 8 years
    Clearly the punch card comparison is wrong, because by the time BASIC was invented, line numbering in, eg, Fortran was optional, and BASIC changed that to make it compulsory, which is what the question is asking about.
  • Jules
    Jules about 8 years
    Also, BASIC was originally implemented as a compiler, not an interpreter (similarly to the way many LISP implementations compile each expression on entry prior to execution), so interpreter internals are irrelevant also.
  • Jules
    Jules about 8 years
    +1 - this is the right answer. The combination of line editor and immediate execution in the same environment was probably BASIC's most important contribution.
  • Jules
    Jules about 8 years
    This was a prototype, implemented as an experiment while the teletype-based interface that the language was being designed for was still being developed. While I have no direct evidence either way, I'd bet that either (a) this first version didn't have compulsory line numbering (like Fortran) or (b) the use of line numbers to provide program editing versus immediate execution had already been planned.
  • Joseph Rogers
    Joseph Rogers about 8 years
    I learned BASIC on an Acorn electron, which had exactly the interface you describe, and I had completely forgotten this! +1 for the memories!
  • phuclv
    phuclv about 8 years
    This was used in this code golf
  • ypnos
    ypnos about 8 years
    @LưuVĩnhPhúc Nice one!