Why did we bother with line numbers at all? [close

2019-01-23 00:48发布

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!

16条回答
爷的心禁止访问
2楼-- · 2019-01-23 01:31

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.

查看更多
Viruses.
3楼-- · 2019-01-23 01:36

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.

查看更多
别忘想泡老子
4楼-- · 2019-01-23 01:39

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.

查看更多
趁早两清
5楼-- · 2019-01-23 01:41

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.

查看更多
疯言疯语
6楼-- · 2019-01-23 01:42

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

查看更多
唯我独甜
7楼-- · 2019-01-23 01:46

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 label takes more memory, first in the location, where that label is defined, then in any jump command.

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

Newer dialects of Basic don't have the need for line numbers any longer.

查看更多
登录 后发表回答