Regularity
From Maze
(Difference between revisions)
(→The Computer Screen) | (→The Harmfulness of GOTO) | ||
| Line 160: | Line 160: | ||
== The Harmfulness of GOTO == | == The Harmfulness of GOTO == | ||
| + | Those aware of the discourse in computer science might turn to 10 PRINT with some trepidation, thanks to a 1986 letter to the editor from Edsgar W. Dijkstra which declares "Go To Statement Considered Harmful" (EWD215). Although the title was actually written by the editor -- Dijkstra calls this article "A Case against the GO TO Statement" -- the letter and the sentiment behind it have gained lasting fame. One author called it "probably the most often cited document about any type of programming" (Tribble 2005). As this author explains, Dijkstra's exhortation | ||
| + | |||
| + | <blockquote>was written at a time when the accepted way of programming was to code iterative loops, if-thens, and other control structures by hand using goto statements. Most programming languages of the time did not support the basic control flow statements that we take for granted today, or only provided very limited forms of them. Dijkstra did not mean that ''all'' uses of goto were bad, but rather that superior control structures should exist that, when used properly, would eliminate ''most'' of the uses of goto popular at the time.</blockquote> | ||
| + | |||
| + | Indeed, there is an obvious control structure, unfortunately absent from BASIC, that would accomplish the purpose of 10 PRINT's GOTO without requiring the use of GOTO. This is the <code>while</code> or <code>do ... while</code> loop, which in this case could simply be used with the condition "True." For instance, if Commodore 64 BASIC had a DO ... WHILE statement, one might write: | ||
| + | |||
| + | <code>10 DO : PRINT CHR$(205.5+RND(1)); : WHILE TRUE</code> | ||
| + | |||
| + | This would certainly be a clearer way to write the program, and it would be widely recognized today as clearer because Dijkstra's view of programming has prevailed. Still, it's not obvious that the tiny program 10 PRINT would have particularly offended Dijkstra. In his letter, he objects to the "unbridled use of the '''go to''' statement" and does not state that every use of it is unambiguously bad. He describes the GOTO-related problems that arise from the values of variables getting out of a programmer's control. But 10 PRINT has no variables, so this particular problem is not an issue. | ||
| + | |||
| + | The equivalent of a GOTO statement is a staple of machine language programming, and in its unconditional form is called JMP. Dijkstra essentially exempted machine language from his critique of GOTO. He recognized that computer programs written in a high level language are more complicated and nuanced ways of expressing thought, not tied directly to machine function. By creating a new sort of language that does not directly mimic the operation of the processor, it is possible to think more flexibly. Although Dijkstra objected to the way BASIC was designed, he worked strenuously to describe how high-level languages could be effective in machine-independent ways. | ||
| + | |||
== BASIC Considered Harmful (Sidebar) == | == BASIC Considered Harmful (Sidebar) == | ||
