BASIC

From Maze

(Difference between revisions)
Jump to: navigation, search
Line 126:Line 126:
== Line Numbers and Colons: BASIC's Responses to Changing Hardware (Sidebar) ==
== Line Numbers and Colons: BASIC's Responses to Changing Hardware (Sidebar) ==
−
Microsoft has used its position as a corporate supporter of BASIC to make many changes to the language, adding and removing components that became necessary or obsolete as hardware progressed. For example, to allow programs to be written more compactly, an important feature given the Altair's switch and toggle interface, which could literally be painful to program, Microsoft's Altair BASIC introduced the colon (:) to place separate statements on the same line. Used this way, the colon allowed lines such as:
+
Microsoft has used its position as a corporate supporter of BASIC to make many changes to the language, adding and removing components that became necessary or obsolete as hardware progressed. For example, to allow programs to be written more compactly -- an important feature given the Altair's switch and toggle interface, which could literally be painful to program -- Microsoft's Altair BASIC introduced the colon (:) to place separate statements on the same line. Used this way, the colon allowed lines such as:
<code>160 R=16:PRINT"HOW MANY DECKS (1-4)";</code>
<code>160 R=16:PRINT"HOW MANY DECKS (1-4)";</code>
−
Multiple statements on the same line was not possible with minicomputer BASICs and the ANSI standard; Kemeny and Kurtz saw the compression of statements as potentially confusing rather than helpful. When they released their much-revised True BASIC for home computers in 1983, they did not allow multi-statement lines. The colon is, however, important to 10 PRINT; this program could not be written as a concise one-liner without it.
+
Multiple statements on the same line were not possible with minicomputer BASICs and the ANSI standard; Kemeny and Kurtz saw the compression of statements as potentially confusing rather than helpful. When they released their much-revised True BASIC for home computers in 1983, they did not allow multi-statement lines. The colon is, however, important to 10 PRINT; this program could not be written as a concise one-liner without it.
−
Another prominent feature of 10 PRINT is also an artifact of the hardware underlying the language. Unlike its punch card-derived predecessors, BASIC didn't require programmers to put things in certain columns; yet there was a requirement that a number, such as "10", appear at the beginning of each line. While line numbers made branching possible by allowing GOTO and GOSUB, BASIC did not technically need line numbers for this purpose. Labels, such as those used in pre-existing languages like assembly, would have sufficed. The line number's real value is seen on a Teletype or other print terminal, or in any environment where full-screen, nonlinear editing is not an option. Line numbers made it easy in those cases to delete existing lines; simply type the line number without any further instructions, and the line disappears. To correct a single existing line, just retype a line with the same line number. To see what code is currently on a particular line, "LIST 50" will do the trick -- although if one had written the line recently, one could also look up or literally "scroll" back to where the line had been printed out.
+
Another prominent feature of 10 PRINT is also an artifact of the hardware underlying the language. Unlike its punch card-derived predecessors, BASIC didn't require programmers to put data in certain columns; yet there was a requirement that a number, such as "10", appear at the beginning of each line. While line numbers made branching possible by allowing GOTO and GOSUB, BASIC did not technically need line numbers for this purpose. Labels, such as those used in pre-existing languages like assembly, would have sufficed. The line number's real value is seen on a Teletype or other print terminal, or in any environment where full-screen, nonlinear editing is not an option. Line numbers made it easy in those cases to delete existing lines; simply type the line number without any further instructions, and the line disappears. To correct a single existing line, just retype a line with the same line number. To see what code is currently on a particular line, "LIST 50" will do the trick -- although if one had written the line recently, one could also look up or literally "scroll" back to where the line had been printed out.
−
The practice of numbering program statements by multiples of five or ten is not merely rhythmic or aesthetic; the insertion of new lines in a program requires that, as the 1964 manual puts it, "the original line numbers <ins>not</ins> be consecutive numbers" (22). Numbering a program 10, 20, 30, and so on ensured that between every existing program statement there was room for nine more. It was an acknowledgement that a program is dynamic rather than fixed and perfect. The ''Commodore 64 User's Guide'' also advises that "it is good programming practice to number lines in increments of 10--in case you need to insert some statements later on" (33).
+
The practice of numbering program statements by multiples of five or ten is not merely rhythmic or aesthetic; the insertion of new lines in a program requires that, as the 1964 manual puts it, "the original line numbers <ins>not</ins> be consecutive numbers" (22). Numbering a program 10, 20, 30, and so on ensured that between every existing program statement there was room for nine more. It was an acknowledgment that a program is dynamic rather than fixed and perfect. The ''Commodore 64 User's Guide'' also advises that "it is good programming practice to number lines in increments of 10--in case you need to insert some statements later on" (33).
While line numbers became an iconic feature of BASIC early in the personal computing era, they also contributed to a perception among programmers that the language is limited to simple tasks. Leaving space to add nine new lines of code between every original line may initially seem like plenty of flexibility, but it is rarely enough when programmers have a complex problem to solve. BASIC can still accommodate this situation by allowing the programmer to use GOTO and GOSUB to jump to as of yet unused numbers for a separate routine and then return to the original program flow when complete. Unfortunately, too many GOTO sub-routines can result in "spaghetti code" -- so named because the flow chart of a program becomes so confused and self-referential that all the lines look like a plate of spaghetti, making the program nearly unintelligible.
While line numbers became an iconic feature of BASIC early in the personal computing era, they also contributed to a perception among programmers that the language is limited to simple tasks. Leaving space to add nine new lines of code between every original line may initially seem like plenty of flexibility, but it is rarely enough when programmers have a complex problem to solve. BASIC can still accommodate this situation by allowing the programmer to use GOTO and GOSUB to jump to as of yet unused numbers for a separate routine and then return to the original program flow when complete. Unfortunately, too many GOTO sub-routines can result in "spaghetti code" -- so named because the flow chart of a program becomes so confused and self-referential that all the lines look like a plate of spaghetti, making the program nearly unintelligible.

Revision as of 11:33, 16 July 2011

View this revision of BASIC.

Personal tools