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:48

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

查看更多
祖国的老花朵
3楼-- · 2019-01-23 01:49

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 :)

查看更多
Bombasti
4楼-- · 2019-01-23 01:50

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!

查看更多
Emotional °昔
5楼-- · 2019-01-23 01:51

Paul Tomblin's answer is the most comprehensive, but I'm surprised no one has mentioned that a big part of the BASIC project's initial goal was to provide a beginner-friendly interactive environment using timesharing. (Kurtz and Kemeny's vision for "universal access for all students" was far ahead of its time in this regard.)

The BASIC system that was developed to fulfill this goal featured Teletype ASR-33 (and later other) printing terminals. When connected to a timesharing-capable OS, these allowed editing and running BASIC programs in an interactive mode (unlike working with punched cards), but they are not cursor-addressable. Line numbers were a beginner-friendly way to both specify the order of program statements and allow unambiguous editing in the absence of a screen editor. The Wikipedia entry for "line editor" explains further, and anyone who's ever tried to use a line editor (such as the Un*x 'ed') can appreciate why Kurtz and Kemeny should be thanked for sparing the beginner having to learn the cryptic command sequences required for editing text in this manner.

查看更多
登录 后发表回答