Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why BASIC had numbered lines? [duplicate]

Tags:

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?

like image 727
Giovanni Funchal Avatar asked Mar 12 '10 20:03

Giovanni Funchal


People also ask

Why did basic have line numbers?

The purpose of line numbers was for branching and for reference by formatting statements. Both JOSS and BASIC made line numbers a required element of syntax.

Are line numbers necessary?

Line numbers also give the developer a quantifiable sense of how long his code is and, in the case of large files, a sense of where in the file he is. Not to mention, line numbers are absolutely essential when doing any sort of partner programming.


1 Answers

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!

like image 126
Ferruccio Avatar answered Sep 24 '22 02:09

Ferruccio