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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public From: mfinney@lynchburg.net Subject: Re: Software landmines (loops) Date: 1998/09/03 Message-ID: #1/1 X-Deja-AN: 387420591 References: <902934874.2099.0.nnrp-10.c246a717@news.demon.co.uk> <6r1glm$bvh$1@nnrp1.dejanews.com> <6r9f8h$jtm$1@nnrp1.dejanews.com> <6renh8$ga7$1@nnrp1.dejanews.com> <6rf59b$2ud$1@nnrp1.dejanews.com> <6rfra4$rul$1@nnrp1.dejanews.com> <35DBDD24.D003404D@calfp.co.uk> <6sbuod$fra$1@hirame.wwa.com> <35f51e53.48044143@ <904556531.666222@miso.it.uq.edu.au> <6sgror$je8$3@news.indigo.ie> <6sh3qn$9p2$1@hirame.wwa.com> <6sk1k9$3r9$1@nnrp1.dejanews.com> X-Complaints-To: Abuse Role , We Care X-Trace: newsread.com 904812385 208.197.56.125 (Thu, 03 Sep 1998 04:46:25 EDT) Organization: Lynchburg.net (lynchburg.net) Reply-To: mfinney@lynchburg.net NNTP-Posting-Date: Thu, 03 Sep 1998 04:46:25 EDT Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-09-03T00:00:00+00:00 List-Id: In <6sk1k9$3r9$1@nnrp1.dejanews.com>, john-clonts@hlp.com writes: >What do you mean by 'tree-structured' programming? If memory serves correctly, one definition of tree-structured programming is those programs that can be written with the following control structures... 1. A named block 2. A "jump" to the start or end of a named block 3. A statement which conditionally executes the following statement Or, if C/C++ did not have a "goto" statement, but instead allowed a do/for/while block to be named and allowed that name to be used with a break/continue statement (you can get an arbitrary block in C/C++ by using a do {/*code*/} while (false); control structure). Then only tree-structured programs could be written (ignoring exceptions). A return statement in C/C++ effectively implements a multi-level break from the current module. The only other way to accomplish it in C/C++ is by using the "goto". Nevertheless, tree-structured programs are structured and can be characterized in a number of ways. Again, if memory serves (all of my references are still packed from my move), a tree-structured program can also be characterized as any program which contains no jumps into a block. For example... outer::while (someCondition) { // some code inner::while (anotherCondition) { // some code outer::break; // exit outermost loop inner::continue; // restart innermost loop outer::continue; // restart outermost loop inner::break; // exit innermost loop // some code } // some code } Here, I am using a notation which is modeled on C++'s "scoping" operator because you want to specify the "scope" which applies to the break/continue. The only difference between tree-structured programming and structured programming is that only a single level break/continue is allowed for structured programming and structured programming only allows a single exit from any block (both tree-structured and structured programming only allow a single entry to a block). The use of "goto" is strictly controlled in a tree-structued program and arbitrary "spaghetti" cannot be written. Knuth has shown that for any given set of control structures, there are some programs which cannot be easily represented. The set of programs which can be easily represented (without using "flag" tricks or other work-arounds) by structured programs is strictly less than the set of programs which can be easily represented by tree-structured programs. I personally believe that the incidence of programs which can be easily represented as tree-structured programs but not structured programs is high enough that restricting oneself to structured programming is not reasonable. That is, of course, a personal judgement call, but I do have a reasonable amount of experience to back it up. While I have found many, if not most, programs don't fit the structured program mold, I have found very few, if any, which do not fit the tree-structured program mold. I have often wished for additional control structures, but every one of them is tree-structured. Michael Lee Finney