
Programming With(out) the GOTO B .M . Leavenworth, IB M A brief history of the goto controversy (retentio n 1. Since transfer of control is subsumed b y or deletion of the goto statement) is presented . more powerful notions, to wit : After considering some of the theoretical an d sequential executio n practical aspects of the problem, a summary o f procedure call and retur n arguments both for and against the goto is given . conditional expression (statement ) repetition clause (for statemen t KEY WORDS AND PHRASES : goto statement, comput- in ALGOL, DO group in PL/I ) ability theory, goto-less programming, combinatory is not the programmer led astray by givin g logic, lambda calculus, Post systems, Markov algo- him control over it ? rithms, Turing machines, structured programming , 2. The solution of the halting problem (th e . control structures determination of whether a given program ter- CR CATEGORIES : 1 .3, 4 .2, 5 . 2 minates) is made difficult by the unrestricte d use of the goto statement . After eliminatio n INTRODUCTION of the goto, there are only two ways in whic h a program may fail to stop : either by infinit e There are a number of issues connected wit h recursion, or by the repetition clause , the retention or deletion of the goto statemen t in programs or programming languages, and w e Val Schorre reported in 1966 (S1) on th e attempt to set the stage for a discussion of thes e development of two procedural languages, LISPX an d issues by giving a brief history of the goto con- MOL-32, without the goto . Further, that he ha d troversy . The possibility of eliminating the got o been writing programs since 1960 in outline for m has both theoretical and practical aspects . It i s using the principle of nested flow . These outlines , of interest to discover that the goto does no t which served the purpose of flow charts, showed th e appear in most formal systems of computabilit y flow of control graphically by indentation, an d theory, but does appear in programming languag e were used as original documentation of the program , extensions of these systems . Since programmin g which was coded in assembly language from the out - style is an important component of the controversy , line . This may be the first recorded instance o f we give one example of the influence of a hig h "goto-less " procedural programming (as distinc t level language on programming style, and its re- from functional programming in LISP), albeit not i n lation to the goto statement . Finally, a summar y a high level language . of arguments both for and against the goto i s Professor Van Wijngaarden (Vl) showed that th e given . goto statement could, in principle, be eliminate d from ALGOL 60 programs by a preprocessing algorith m HISTORY which replaced the set of given programming con- structs by a smaller set of equivalent concepts . The proposition that there might be somethin g The purpose of this demonstration was the expli- wrong with the goto statement, one of the pillar s cation of syntax and semantics, rather than 'goto- of practical programming since the invention o f less " programming . FORTRAN, has slowly penetrated the consciousnes s Peter Landin also argued in 1966 (L3) for a of programmers since Dijkstra ' s famous letter i n style of programming which eliminates not only th e the Communications of the ACM (D4) . Actually , goto, but the notion of explicit sequencing an d Professor Dijkstra considered programming language s assignment as well . Landin introduced a languag e without benefit of either assignment or goto in a called ISWIM, and used a purely functional subse t paper presented at the 1965 IFIP Congress (D2) . H e of this language to program in this style . I t concluded that a language without the former wa s should be noted, however, that ISWI?I contains im- elegant but inadequate . As to the latter, he enun- perative features such as " program points " , roughl y ciated the criterion that the quality of a program- analogous to labels, and assignment so that th e mer was inversely proportional to the density o f programmer has an out . We shall see that thi s 2oto statements in his program . While admittin g theme constantly recurs in what follows . the possibility of a conflict between convenienc e and efficiency, he made the following points, whic h COMPUTABILITY THEORY WITH[OUT] THE GOT O are paraphrased below, Although the formal systems of computabilit y theory (see below) have for the most part theo - 54 retical rather than practical significance, they statements in ALGOL and PL/I so that they coul d demonstrate that the goto is not needed as a prim- write itive in order to compute all computable functions . IF expr THEN DO It is interesting to discover, however, that th e ; . ' END ; goto has been included in pragmatic extensions t o continued to writ e these systems . The goto does not appear in the following for - IF expr THEN GO TO LAB ; mal systems : from force of habit . Thus we see the influenc e that machine primitives have exerted through th e Formal System programming Extensio n present evolution of high level programming lan- combinatory logic of a jumping operator ' J ' guages ! Curry & Feys (Cll), and was defined by Landi n the lambda calculus of (L3) in ISWIN, which i s SUMMARY OF ISSUE S Church (C4) an extension of th e lambda calculu s Since the theoretical possibility of elimi - nating the goto has been demonstrated, it wil l Post systems (P5) and labelled Markov algor - not be discussed further . We will therefor e Narkov algorithms (Ml) ithms with branchin g attempt to summarize the practical arguments bot h were defined by Cara- for and against the goto . The arguments for elimi - cciolo et al (Cl), an d nating the goto (at the same time, replacing it b y the language CO>IIT (Yl ) other control structures) are essentially the fol- and SNOBOL (Fl) can b e lowing : considered to be exten- 1 . Goto-less sions of Markov algor - programs are easier to understand , ithms with goto command s debug and modify . This is the structured o r top-down programming argument (D2) (D4) (D6 ) Kleene general recur- LISP (212), which was als o (ES) (W7) (W8) (W9) . sive functions (Kl) strongly influenced b y the lambda calculus, ha s 2, If the goto statement is not replaced b y more sophisticated control structures, th e the PROG feature which allows assignment an d programmer is likely to misuse it (the goto. ) goto (see below ) in order to synthesize those structures (D4 ) (W9) . We see in each case that the goto is missing i n 3 . It is easier to prove assertions about " goto- the pristine form of the system, but has been adde d less " programs (L3) (P3) (S3) . in programming extensions (whether for the sake o f tradition or " convenience" is a matter for debate) . The technical means of replacing gotos b y The FROG feature (B5) was added to LISP in order t o other control structures are as follows : incorporate the goto, among other things, althoug h 1. by recursive procedures . This is a theo- a wide range of applications have been written i n retical, rather than a practical, device (V1 ) pure (no assignment or goto) LISP . (K2) . The goto appears in Turing machines (Ti) (sinc e instructions or states have explicit successors) , 2. by the while construction . This can al - and related automata such as Minsky's program ma - ways be done without changing the progra m chines (M6) . It also appears in program schemat a topology, by the introduction of auxiliary (L7), which can be characterized as flow charts wit h variables (Al) . assignment statements in the boxes . And finally , 3. by node splitting . This requires redundan t it appears in the order codes of the general pur- code or procedure calls (K2) (W7) . pose computer . The arguments against eliminating the goto ca n THE INFLUENCE OF NOTATIO N be surmarized as follows : 1. the goto is needed for abnormal exits fro m It may be truly said that the goto statement i n a block or procedure . The ' repeat-exit' mech- its form as a machine primitive has profoundly in- anism of Knuth and Floyd (K2) only allows a one - fluenced the long line of procedural high level lan- level exit, whereas Wulf ' s leave constructio n guage descendants . We wish to explore this poin t 0?7) requires the reintroduction of labels fo r and its relation to what shall be called the FORTRA N multi-level exits . As Landin (L3) has admitted , II IF Syndrome . " the most recalcitrant uses of explicit sequenc- The FORTRAN II IF statement --- IF (expr ) ing appear to be associated with success/failur e nl, n2, n3 ---- is a prime example of the power o f situations and the action needed on failure , language to influence program organization, an d probably corrupted a generation of programmers . 2. the goto is often more efficient . For, con- sider the overhead introduced by node splittin g This statement effectively generates multiple goto s (which reflect the unconditional transfers in ma - and the while construction (setting of flags) . Also, Knuth and Floyd (K2) have pointed out tha t chine code), as can be seen by the equivalent PL R procedure calls can sometimes be replaced b y statements : goto statements . IF expr < 0 THEN GO TO nl ; IF expr = 0 THEN GO TO n2 ; 3.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-