views:

530

answers:

16

Possible Duplicate:
Why did we bother with line numbers at all?

I'm curious about why early versions of the BASIC programming language had line numbering like in:

42 PRINT "Hello world!"

The text editors back then had no line numbering?

EDIT: Yes, I know they are used for GOTOs, but why? I mean having labels was too computationally expensive?

+8  A: 

They were used as labels for GOTO and GOSUB

Like this:

10 PRINT "HELLO WORLD"
20 GOTO 10

There were no named labels in some early BASIC versions

They were also required if you wanted to insert a line between 2 existing lines of code, because in the early days, you had no full text editors. Everything had to be typed in the "interactive" interpreter.

So if you typed:

15 PRINT "AND THE UNIVERSE"

The program would become:

10 PRINT "HELLO WORLD"
15 PRINT "AND THE UNIVERSE"
20 GOTO 10

When you ran out of line numbers, you could run a "renumbering" tool to renumber all lines in your program, but in the very early days of the Commodore 64 and other home computers, we didn't even have that, so you'd have to renumber manually. That's why you had to leave gaps of 10 or more in the line numbers, so you could easily add lines in between.

If you want to try out the Commodore 64 interpreter, check out this C64 emulator written in Flash: http://codeazur.com.br/stuff/fc64_final/ (no install required)

Philippe Leybaert
("So if you typed") Can you name the text editor you are referring to please?
Helltone
There was no text editor. Just a command line where you would type your code
Philippe Leybaert
Yes but is there any name for this command line? I can't find any reference of it on the web, no screenshot, nothing.
Helltone
@Helltone: BASIC was an interpreted language. You typed into the interpreter.
John Saunders
@JohnFx: What "edlin" are you talking about? What platform was that?
John Saunders
@Helltone: try one of the many Commodore 64 emulators. It's fun to live in the past for a few minutes :-) There's even a FLASH version of an emulator: http://codeazur.com.br/stuff/fc64_final/
Philippe Leybaert
@John edlin was a line editor that came with the first version of MS-DOS - it had nothing to do with BASIC.
anon
@Neil: I'm so confused. So why are we talking about edlin in conjunction with BASIC, which predates MS-DOS by over a decade?
John Saunders
@John "edlin" was a specific (microsoft) product - a "line editor" is a generic idea for how to edit text.
anon
edlin was a line oriented editor for editing files, but you had to select which line to edit and then edit it. Early BASIC interpreters (WAY before edlin came about) used the screen buffer as a pseudo-history buffer. You could edit a single line by moving the cursor to the line you wanted to edit, make some changes and press enter. When you were good at it, it was pretty powerful :) Those were the days...
Philippe Leybaert
@John and actually "edlin" is still available in Windows, at least as of Win2K, which I'm running at this moment. Open a command line prompt and type "edlin foo.txt" to get a taste of its fantastic user interface.
anon
@Neil: I've used edlin to write C programs for the IBM PC XT.
John Saunders
+2  A: 

The line numbers were used in control flow. There were no named subroutines. You had to use GOSUB 60, for instance, to call the subroutine starting at line 60.


On your update, not all languages had labels, but all languages had line numbers at one time. At one time, everything was punch cards. BASIC was one of the very first interactive languages, where you could actually type something and have a response immediately. Line numbers were still the current technology.

Labels are an extra expense. You have to keep track of the correlation between the symbolic label and the code or data to which it refers. But if every line has a line number (and if all transfer of control flow statements always refer to the beginning of a line), then you don't need a separate symbol table.

Also keep in mind that original BASIC interpreters didn't need a symbol table for variables: There were 26 variables named A-Z. Some were sophisticated and had An-Zn. Some got very fancy and added a distinction between string, integer and floating point by adding "$" or "%" after the variable. But no symbol table was required.

John Saunders
The issue wasn't "radical" -- assemblers had labels long before Algol-60 used them. It's the "multiple-pass" resolution of labels. Early assemblers (and compilers) had to read the entire program source several times to resolve label names. It was just slow.
S.Lott
@S.Lott: I seem to have lost my "ALGOL-60" comment.
John Saunders
Reason for the downvote, please.
John Saunders
+1  A: 

IIRC, line numbers were mostly used as labels for GOTO and GOSUB statements, since in some (most?) flavors of BASIC there was no way to label a section of code.

Frank Schmitt
+9  A: 

The original BASIC line numbering was actually an integral part of the language, and used for control flow.

The GOTO and GOSUB commands would take the line, and use it for control flow. This was common then (even though it's discouraged now).

Reed Copsey
While your answer is not wrong, a more complete answer would indicate that the lack of interactive text editors made line numbering a necessary evil; so that one could insert additional lines of code between previously entered lines.
@roygbiv: that was indeed the most important reason for the existence of line numbers in BASIC
Philippe Leybaert
@Philippe: "an important reason", not the most important. Programs were not interesting without GOTO or GOSUB.
John Saunders
Don't forget that line numbers were useful for debugging because the compiler/runtime would report back the line number in question when a syntax error/exception occurred.
Nissan Fan
There were many reasons for line numbering, mainly historic. The interactive editing was a useful reason, but not the only one....
Reed Copsey
@roygbiv: That is a specific interpreter's implementation detail - there were BASIC flavors that actually read from files instead of being interactive, even in very early versions, and they still required line numbers.
Reed Copsey
So far in this thread there are two reasons: GOTO/GOSUB and editing... `what are some other reasons?`
@John: you're right. Wrong wording. There were 2 main reasons: line ordering and labeling for GOTO and GOSUB
Philippe Leybaert
+7  A: 

In BASIC, the line numbers indicated sequence.

Also, many older editors weren't for files, but simply lines ("line editors", e.g. ed, the standard editor). By numbering them this way, you knew which line you were working on.

fatcat1111
+3  A: 

They were labels for statements, so that you could GOTO the line number. The number of the statements did not necessarily have to match the physical line numbers in the file.

Mike Daniels
In fact it was common and pretty much necessary to leave gaps of 5-10 to allow for additions to be made without having to renumber the whole program.
Buggabill
A: 

Hi

This wiki page explains some what about the line numbers.

cheers

Andriyev
+1  A: 

They were also used by the editor - ie you said:

edit 100

to edit line 100.

anon
@Neil: You had an _editor_? We didn't need any _editor_! We just typed the line over again.
John Saunders
@John All versions of BASIC that I ever used, from the original Dartmouth BASIC, had a built in line editor. Certainly the ones from Microsoft (many versions) and the one on the DEC-System 10 (which is about as retro as you can get) did.
anon
@Neil: was that a "line editor", or was it the interpreter? Was it a separate program? How did you start it?
John Saunders
Can I propose a new version of Godwin's law? the first person to make a comment that devolves into the 4 Yorkshiremen sketch loses.
Martin Beckett
@John You typed "BASIC" and then you were in the BASIC environment, which had a line editor. Or on microprocessor systems like (say) the Tandy CoCo or the BBC Nicro you booted immediately into the BASIC environment, also with a line editor built-in. Which version of BASIC were you using that didn't have one?
anon
@John I think we may be quibling about the meaning of "line editor" - I agree that some very basic BASICs had no way of recalling the line you were trying to edit.
anon
@Neil: I suppose it might have been called the editor, but it wasn't a separate program.
John Saunders
@John I didn't say it was. The editor in a modern IDE is not a separate program, but it is still called an editor.
anon
@Neil: it's an issue of timeframe. Remember what an "edit report" was? At one time, maybe "editor" meant "those commands you use to edit". Today, the word is more likely meant to refer to a separate program.
John Saunders
Thanks for the really nice comment
Helltone
+1  A: 

As others have pointed out, these line numbers were used as part of subroutines.

Of course, there's a reason that this isn't done anymore. Imagine if you say GOTO 20 on line 10, and then later realize you need to write 10 more lines of code after line 10. All of a sudden, you're smashing up against 20 so you either need to shift your subroutine farther away (higher numbers) and change your GOTO value, or you need to write another subroutine that jumps farther in the code.

In other words, it became a nightmare of true spaghetti code and is not fun to maintain.

JasCav
+5  A: 

Back in the day all languages had sequence numbers, everything was on punched cards. There was one line per card. Decks of cards made up your program.

When you dropped the cards, you'd put them in a card sorter that used those sequence numbers.

And of course, they were referenced by control flow constructs.

mrmacbob
amusing as well as correct!
Jennifer Zouak
You should probably provide a link to say what punched cards are, because based on most of the other answers, most people here are unfamiliar with them.
Gabe
+1  A: 

Some editors only had an "overwrite" mode and no "insert" mode. This made editing of existing code extremely painful. By adding that line-number feature, you could however patch existing code from anywhere within the file:

100 PRINT "Broken Code"
200 PRINT "Foobar"
...
101 patch the broken code
102 patch more broken code

Because line numbers didn't have to be ordered within the file.

zneak
+4  A: 

On the C64, there wasn't even a real editor (built-in at least). To edit a part of the program, you'd do something like LIST 100-200, and then you'd only be able to edit those lines that were currently displayed on the screen (no scrolling upwards!)

Chris Lercher
Do you have any reference for this 'editor'?
Helltone
Yes - the editor was basically the screen memory, quite common on 8bit machines back then.
Martin Beckett
Well, it was part of the interpreter that started as soon as the C64 was turned on. It was part of the unmodifiable ROM (and it left you only with about 40k of the 64k total RAM, because it had to be copied into RAM first). It was used as a basic shell (to load programs etc), too. Maybe you want to try a C64 emulator (http://en.wikipedia.org/wiki/List_of_computer_system_emulators#Commodore_64) - it's fun :-)
Chris Lercher
+6  A: 

A simple google reveals what wikipedia has to say about it:

Line numbers were a required element of syntax in some older programming languages such as GW-BASIC.[2] The primary reason for this is that most operating systems at the time lacked interactive text editors; since the programmer's interface was usually limited to a line editor, line numbers provided a mechanism by which specific lines in the source code could be referenced for editing, and by which the programmer could insert a new line at a specific point. Line numbers also provided a convenient means of distinguishing between code to be entered into the program and commands to be executed immediately when entered by the user (which do not have line numbers).

@Helltone - If this does not answer your question, then none of the answers, answer your question.
@S.Lott I don't think it is arrogant to ask here. Most of us don't have access to Kurtz. Do you?
aaaa bbbb
@zneak - My comment refers to the fact that Helltone had downvoted my post with a comment that said 'This doesn't answer my question.' He has since deleted that comment. My response simply indicates that my answer encapsulates what others are saying, therefore labeling this answer as 'wrong' is implicitly labeling everyone else's answers as wrong. It has nothing to do with arrogance.
@roygbiv: Oh, I'm sorry then. I'll delete my comment.
zneak
+1  A: 

It was entered in on the command-line in many instances (or was, on my old Commodore 64) so there might not always have been a text editor, or if there was, it was quite basic.

In addition, you would need to do GOTOs and the like, as well as inserting lines in between others.

ie:

10 PRINT "HELLO"
20 GOTO 10
15 PRINT " WORLD"

where it would go in the logical 10 15 20

Slokun
+12  A: 

Many microcomputers had a BASIC interpreter in ROM that would start upon bootup. The problem was that there was no text editor or file system to speak of. You had an interactive prompt to do everything through. If you wanted to insert a line of code, you just typed it, starting with the line number. It would insert it into the correct spot in you code. e.g:

>10 print "hello"
>30 goto 10
>20 print "world"
>list
10 PRINT "hello"
20 PRINT "world"
30 GOTO 10
>

(In that example > is the BASIC prompt)

If you wanted to erase a line, you would type something like ERASE 20. Some really fancy systems gave you a line editor (i.e. EDIT 10) And if you didn't plan your line numbers and ran out (how do I insert a line between 10 and 11?) some systems gave you a RENUM command which would renumber your code (and adjust GOTOs and GOSUBs appropriately).

Fun Times!

Ferruccio
Not only that but there was no internet in those days. You wanted to access a computer you _walked_ to where it was. Uphill. Both ways. And when Ferruccio says no filesystem, that's _no_ as in no permanent storage at all on the earliest microcomputer systems. Turn it off, everything's gone. Eventually we got the capability to save programs on cassette tape. Sometimes you could even reload the program from the tape, if you managed to get the level right.
Hugh Brackett
+1  A: 

Line numbers were a PART of the language, in some VERY early ones, even the OS was just these simple lines. ALL you had was one line at a time to manipulate. Try writing an accounting system using 1-4k program files and segmenting it by size to get stuff done. To edit you used the line numbers to tell what you were editing. So, if you entered like:

10 PRINT "howdy"
20 GOTO 10
10 PRINT "WOOPS"
15 PRINT "MORE WOOPS"
20
RUN

YOU WOULD GET:

WOOPS
MORE WHOOPS

The blank 20 would effectivly delete that line.

Mark Schultheiss