Regularity
From Maze
(Difference between revisions)
(→The Harmfulness of GOTO) | (→The Harmfulness of GOTO) | ||
| Line 164: | Line 164: | ||
<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> | <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: | + | 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" so that the loop would always repeat 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> | <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. | + | 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 when the values of variables getting out of a programmer's control. But 10 PRINT has no variables, so this particular problem with GOTO 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. | + | The equivalent of a GOTO statement is a staple of machine language programming; it is the unconditional branch, 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 for programmers to think more flexibly and powerfully. Although Dijkstra objected to the way BASIC was designed, he, like the original designers of BASIC, worked strenuously to describe how high-level languages, useful for thinking about computation, could work in machine-independent ways. |
== BASIC Considered Harmful (Sidebar) == | == BASIC Considered Harmful (Sidebar) == | ||
