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: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public From: "Robert Martin" Subject: Re: Software landmines (loops) Date: 1998/08/31 Message-ID: <6sdiav$e0g$1@hirame.wwa.com>#1/1 X-Deja-AN: 386352646 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@news.erols.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: WorldWide Access - Midwestern Internet Services - www.wwa.com Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada Date: 1998-08-31T00:00:00+00:00 List-Id: Ell wrote in message <35f51e53.48044143@news.erols.com>... >"Robert Martin" wrote: > >>Matthew Heaney wrote in message ... >>> >>>If theory says use a construct, but observation reveals that programmers >>>who use the construct produce more errors, then the theory needs to be >>>thrown out. > >>All else being equal, that would be so. But when observation shows that the >>construct reduces the overall cost of maintaining the program, regardless of >>its initial cost, then it ought not be thrown out. > >Yes if what you say is true then we should keep it, but he is saying >that programmers who use it are producing more errors. Do you grasp >that, or will you insist on stating groundless tautologies? I grasped it. I am skeptical, but I grasped it. Now, do you grasp that initial programmer errors may not be as serious as latter maintenance problems? If we accept that mid loop breaks reduce initial errors by programmers (something that I have serious doubts about) then if they also cause severe subsequent maintenance problems, they should still be avoided. On the other hand, if the errors produced by single exit loops are fixed once, and then the structures afford easier maintenance, then it may still be best to keep them. > >>>For example, there's a pernicious myth that exiting (or returning) from >>>the middle of a loop is bad, and that the only proper way to write a >>>loop is to state the termination condition explicitly, as a predicate >>>appearing at the top of the loop. > >>Yes. That pernicious myth is called "structured programming". > >Please cite even just a single structured programming text, or founder >where what you say here was asserted. "Structured Programming", Dijkstra, Dahl, Hoare, Academic Press, 1972. p. 16-23 "7. On Understanding Programs". Actualy this section says that there are two different kinds of loops. one that is tested at the top; and another which is tested at the bottom. But in all cases, the elements of structure programming have a single entry and a single exit. A loop that exits in the middle, violates this maxim. > >>>The researchers found that the exit-from-the-middle construct had a >>>better "cognitive fit" than the other constructs. > >>"Cognitive fit" is probably not a very good criterion for good engineering. >>GOTO has a very good cognitive fit. So does a flat Earth. > >I would assert that 'goto' spaghetti coding is only a cognitive fit to >you, and handful of others, not most of us. I contend that people are more disposed to write spaghetti, than to take the time and think through the structure of their code. The evidence for this is the vast array of poorly structured programs that have accumulated over the years. Indeed, most novices write *horrible* code, and only gain the ability to structure it well after making the mistakes and experiencing the cost. Therefore I content that spaghetti is the natural state, and that it requires experience and dedication to produce non-spaghetti. Now, I'll grant you that spaghetti is does not have a good cognitive fit with the reader of the code. However, the spaghetti had a very good cognitive fit with the *writer* of the code. Robert C. Martin | Design Consulting | Training courses offered: Object Mentor | rmartin@oma.com | Object Oriented Design 14619 N Somerset Cr | Tel: (800) 338-6716 | C++ Green Oaks IL 60048 | Fax: (847) 918-1023 | http://www.oma.com "One of the great commandments of science is: 'Mistrust arguments from authority.'" -- Carl Sagan