From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,9a0ff0bffdf63657 X-Google-Attributes: gidfac41,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Software landmines (loops) Date: 1998/09/05 Message-ID: X-Deja-AN: 388218471 Sender: matt@mheaney.ni.net References: <35f23ce2.7649859@news.erols.com> <6snn1b$c90$1@hirame.wwa.com> <35ef7dff.24318728@news.erols.com> <35f79e53.98130474@news.erols.com> NNTP-Posting-Date: Sat, 05 Sep 1998 11:58:07 PDT Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-05T00:00:00+00:00 List-Id: jdege@jdege.visi.com (Jeffrey C. Dege) writes: > These two quotes do not, admittedly, demonstrate that Dijkstra advocated > se/se as a part of structured programming. They do, however, explain > why Robert and Patrick are so adamanent about the idea that se/se is > a part of structured programming, because the authors of the college > textbooks said so. > > It is certainly possible that Dijkstra didn't stress se/se in his > original work on structured programming. The only one of his early > works on the subject I have access to is his GOTO letter, which > doesn't begin to explore the consequences of the idea. But what > is certainly true is that the programming profession, for a great > many years now, has considered se/se one of the fundamental > principles of structured programming. The best answer to the question "What is structured programming?" was provided by David Gries, in Chap 6, On Structured Programming, of his book Programming Methodology (Springer-Verlag, 1978). The chapter begins with the statement: "The term structured programming has been used with many different meanings since Edsger W. Dijkstra first coined the term. Actually, the term appeared in the title of his monograph Notes On Structured Programming [that's the "little black book" - matt], but as far as I can determine not in the monograph itself!" So Dijkstra never precisely defined the term "structured programming." Next sentence in Gries: "The lack of a precise definition has allowed, even encouraged, people to use it as they wished, to attribute to sp ["sp" is how Gries abbreviates "structured programming" - matt] what they themselves learned from reading Notes On Structures Programming, however different this might have been from Dijkstra's intent." Now we're getting warm. Ed Yourdon other authors have stated that structured programming means single entry/single exit modules, but did Dijkstra say this specifically? The answer would appear to be no. (I myself have the little black book around, and I'm going to make it a point to re-read it. Sadly, this classic text is long out of print, but I was able to find one in a used bookstore.) Next sentence of Gries: "Taken out of context or viewed in the wrong light, some of the resulting definations of sp that have appeared in the literature seem stupid (e.g., sp is programming without gotos), and it is quite understandable that programmers have looked askance when asked to learn and practice it." Gries lists impressions that various people have of sp. Here are some of them: (start of quote) 1. It is a return to common sense. 2. It is the general method by which our leading programmers program. 3. It is programming without the use of goto statements. 5. It is top down programming 6. sp theory deals with converting arbitrarily large and complex flowcharts into standard forms so that they can be represented by iterating and nesting a small number of basic and standard control logic structures (these usually being sequencing, alternation, and iteration) 7. sp is a manner of organizing and coding programs that makes that programs easily understood and modified 8. The purpose of sp is to control complexity through theory and discipline 9. sp should be characterized not by the absence of gotos, but by the presence of structure 10. A major function of the structuring of the program is to keep a correctness proof feasible [this one comes from Dijkstra, in Notes On Structured Programming] 11. A fundamental concept (of sp) is a proof of correctness. 13. sp is no panacea--it really consists of a formal notation for orderly thinking, an attribute not commonly inherent in programmers or any other type... (end of quote) Take a close look at item 10, from Dijkstra himself. Dijkstra stated in his original ACM letter is that there is a "conceptual gap between the static program and the dynamic process." His complaint was that an _unstructured_ program made it hard to reason about the program's behavior. What some advocates of the se/se policy seem to be forgetting is that the whole point is being able to mentally reason about behavior. By reading the program text, can you figure out what this program does? I provided a couple of simple examples, one of them an idiom for using a special input value to terminate a loop: loop Get (N); exit when N = 0; end loop; Is there anyone who doesn't understand what this code fragment does? Structured programming means keeping the code simple, where "simple" means "being able to easily tell what it does." It means being able to prove that it's correct. See item 7. In spite of the fact that this loop exits from the middle, I would argue that it does indeed fit the defination of a "structured" program. We've been debating whether a program that terminates a loop from the middle, or does an early return, is really a "structured" program, but I think this misses the point. We should instead be asking, Can I mentally reason about this program's behavior? Am I able to write a correctness proof for this program? Am I confident that this program works? That's the real meaning of "structured." Back to Gries: "Let me give C. A. R. Hoare's definition, which I feel captures the essence of sp: "The task of organizing one's thought in a way that leads, in a reasonable time, to an understandable expression of a computing task, has come to be called sp."" Again, I would argue that in my comparision operation, even though it terminates via multiple returns, can indeed be called a "structured" program, because it's "an understandable expression of a computing task." I chose the implementation I did precisely because it simplifies mental reasoning about its behavior. When I get the answer, deliver it NOW, without trying to navigate a circuitous route to the end of the subprogram, only to deliver it THEN. Two more lines I'd like to quote from Gries: "I would add to this that one should always strive for simplicity and elegance. The simplest solution is always the easiest to understand."