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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no 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: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,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: #1/1 X-Deja-AN: 388243369 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 13:57:10 PDT Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-05T00:00:00+00:00 List-Id: Matthew Heaney writes: > 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. I've been flipping through Structured Programming, by Linger, Mills, and Witt (Addison-Wesley, 1979), which I read a couple of years ago. In Chap 3 they list a few control structures, among them: (start of quote) The dowhiledo structure has general form do1 dopart1 while whiletest do2 dopart2 od The dowhiledo below prints individual characters from a string, up to a blank character: do1 get next character from string while character not blank do2 print character od (end of quote) Except for the sense of the whiletest, this is the similar to the Ada fragment I presented earlier. For example: loop Get (From => S, Char => C); exit when C = ' '; Put (C); end loop; So we see that the middle exit loop construct really does fit the definition of "structured." Harlan Mills was a mathematician who believed in writing provably correct programs, and his book Structured Programming shows how to do that for, among other loops, the dowhiledo form. The dowhildo form is discussed again on p116-7, in the section on prime programs. His definition (p118) of structured programming is: (start of quote) Definition: A structured program is a compound program constructed from a fixed basis set of prime programs. (end of quote) In other words, his basis set forms a set of axioms, from which program behavior can be derived. He includes the dowhiledo form in his set of axioms. Conclusion: Feel free to exit from the middle of a loop. This form of loop stands as a peer to other forms, among them the whiledo and dountil constructs. If anyone argues that "oh, but it's not structured," then hand them a copy of Mills' book. Software Productivity (Dorset House, 1988) is a collection of Mills' papers. Highly recommended!