正在加载图片...
Edgar Dijkstra:Go To Statement Considered Harmful Go To Statement Considered Harmful dynamic progress is only characterized when we also give to which Key Words and Phrases:go to statement,jump instruction, call of the procedure we refer.With the inclusion of procedures branch instruction,conditional clause,alternative clause,repet- we can characterize the progress of the process via a sequence of itive clause,program intelligibility,program sequencing textual indices,the length of this sequence being equal to the dynamic depth of procedure calling CR Categories:4.22,5.23,5.24 Let us now consider repetition clauses (like,while B repeat A EDITOR: or repeat A until B).Logically speaking,such clauses are now For a number of years I have been familiar with the observation superfuous,because we can express repetition with the aid of that the quality of programmers is a decreasing function of the recursive procedures.For reasons of realism I don't wish to ex- density of go to statements in the programs they produce.More clude them:on the one hand,repetition clauses can be imple- recently I discovered why the use of the go to statement has such mented quite comfortably with present day finite equipment;on disastrous effects,and I became convinced that the go to state- the other hand,the reasoning pattern known as "induetion" ment should.be abolished from all "higher level"programming makes us well equipped to retain our intellectual grasp on the languages (i.e.everything exeept,perhaps,plain machine code). processes generated by repetition clauses.With the inclusion of At'that time I did not attach too much importance to this dis- the repetition clauses textual indices are no longer sufficient to covery;I now submit my considerations for publication because describe the dynamic progress of the process.With each entry into in very recent discussions in which the subject turned up,I have a repetition clause,however,we can associate a so-called "dy- been urged to do so. namic index,"inexorably counting the ordinal number of the My first remark is that,although the programmer's activity corresponding current repetition.As repetition clauses (just as ends when he has constructed a correct program,the process procedure calls)may be applied nestedly,we find that now the taking place under control of his program is the true subject progress of the process can always be uniquely characterized by a matter of his activity,for it is this process that has to accomplish (mixed)sequence of textual and/or dynamic indices. the desired effect;it is this process that in its dynamic behavior The main point is that the values of these indices are outside has to satisfy the desired specifications.Yet,once the program has programmer's control;they are generated (either by the write-up been made,the "making"'of the corresponding process is dele- of his program or by the dynamic evolution of the process)whether gated to the machine. he wishes or not.They provide independent coordinates in which My second remark is that our intellectual powers are rather to describe the progress of the process. geared to master statie relations and that our powers to visualize Why do we need such independent coordinates?The reason processes evolving in time are relatively poorly developed.For is-and this seems to be inherent to sequential processes-that that reason we should do (as wise programmers aware of our we can interpret the value of a variable only with respect to the limitations)our utmost to shorten the conceptual gap between progress of the process.If we wish to count the number,n say,of the static program and the dynamic process,to make the cor people in an initially empty room,we can achieve this by increas- respondence between the program (spread out in text space)and ing n by one whenever we see someone entering the room.In the the process (spread out in time)as trivial as possible. in-between moment that we have observed someone entering the Let us now consider how we can characterize the progress of a room but have not yet performed the subsequent increase of n, process.(You may think about this question in a very concrete its value equals the number of people in the room minus one! manner:suppose that a process,considered as a time succession The unbridled use of the go to statement has an immediate of actions,is stopped after an arbitrary action,what data do we consequence that it becomes terribly hard to find a meaningful set have to fix in order that we can redo the process until the very of coordinates in which to describe the process progress.Usually, Bame point?)If the program text is a pure concatenation of,say people take into account as well the values of some well chosen assignment statements(for the purpose of this discussion regarded variables,but this is out of the question because it is relative to as the descriptions of single actions)it is sufficient to point in the the progress that the meaning of these values is to be understood program text to a point between two successive action deserip- With the go to statement one ean,of course,still describe the tions.(In the absence of go to statements I can permit myself the progress uniquely by a counter counting the number of actions syntactic ambiguity in the last three words of the previous sen- performed since program start (viz.a kind of normalized clock). tence:if we parse them as"successive (action descriptions)"we The difficulty is that such a coordinate,although unique,is utterly mean successive in text space;if we parse as"(successive action) unhelpful.In such a coordinate system it becomes an extremely descriptions"we mean successive in time.)Let us call such a complicated affair to define all those points of progress where pointer to a suitable place in the text a "textual index." say,n equals the number of persons in the room minus one! When we include conditional clauses (if B then A),alternative The go to statement as it stands is just too primitive;it is too clauses(if B then Al else A2),choice clauses as introduced by much an invitation to make a mess of one's program.One can C.A.R.Hoare (caseli]of(A1,A2,...,An)),or conditional expres regard and appreciate the clauses considered as bridling its use.I sions as introduced by J.MeCarthy(B1→E1,B2→E2,·, do not claim that the clauses mentioned are exhaustive in the sense Bn-En),the fact remains that the progress of the process re- that they will satisfy all needs,but whatever clauses are suggested mains characterized by a single textual index. (e.g.abortion clauses)they should satisfy the requirement that a As soon as we include in our language procedures we must admit programmer independent coordinate system can be maintained to that a single textual index is no longer sufficient.In the case that describe the process in a helpful and manageable way. a textual index points to the interior of a procedure body the It is hard to end this with a fair acknowledgment.Am I to Volume 11 Number 3/March,1968 Communications of the ACM 147 Edgar Dijkstra:Go To Statement Considered Harmful 1Edgar Dijkstra: Go To Statement Considered Harmful 1 Edgar Dijkstra: Go To Statement Considered Harmful
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有