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: f43e6,9a0ff0bffdf63657 X-Google-Attributes: gidf43e6,public X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,9a0ff0bffdf63657 X-Google-Attributes: gid1108a1,public From: adam@irvine.com Subject: Re: Software landmines (was: Why C++ is successful) Date: 1998/08/20 Message-ID: <6rfra4$rul$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 382804281 References: <6qfhri$gs7$1@nnrp1.dejanews.com> <35cb8058.645630787@news.ne.mediaone.net> <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> Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Aug 20 00:40:36 1998 GMT Newsgroups: comp.lang.eiffel,comp.object,comp.software-eng,comp.lang.ada X-Http-User-Agent: Mozilla/3.0 (X11; I; Linux 2.0.18 i586) Date: 1998-08-20T00:00:00+00:00 List-Id: In article , "Dan Higdon" wrote: > > adam@irvine.com wrote in message <6rf59b$2ud$1@nnrp1.dejanews.com>... > > > > >Now, here are a couple arguments on the other side: > > > > >(2) (This one is about "continue", since Charles Hixson later argued > >that this was also superior to "goto" for the same reasons.) If > >you have a loop that looks like: > > > > while (blah-blah) { > > some-if-statements... > > some-more-if-statements... > > > > xxx; > > yyy; > > zzz; > > } > > > >someone reading the program might assume that xxx, yyy, and zzz are > >always going to happen before the loop repeats. So if there's > >something new that needs to be done during every loop iteration, it > >looks like you can just add it to the end of the loop, after zzz. > >If there's a "continue" statement somewhere above that, this > >assumption is incorrect and your modification may well be wrong. If > >you replace the "continue" with a "goto", at least there will be a > >label somewhere toward the bottom of the loop, alerting you to the > >fact that you will have to decide whether to put the new code > >before or after the label, or look for the place where this label > >is goto'ed. In fact, this is exactly why I stopped using > >"continue" when I was a C programmer. (I didn't replace them with > >goto's, I used Boolean flags instead.) > > So, you've actually changed the algorithm of your code, added an > unnecessary data item and added yet another compare/branch to avoid > a well understood (IMHO) construct of the C language? Perhaps I'm > the only one who thinks writing code that will execute efficiently > is equally important as writing readable code. If I didn't care > about efficiency, I sure wouldn't be using a 3rd generation > procedural language (OO or not) - there are (IMHO) many more > succinct and mathematically rigorous languages out there than C or > Eiffel (ML and Haskell come to mind, niether of which have gotos, > fwiw). Well, I might have used GOTO if I had to do it over again. My early training taught me to avoid them, and this avoidance has become kind of ingrained. I still probably wouldn't use "continue", however. However: #1: Adding a flag in the manner I've described does not change the algorithm, it merely changes the way the flow of control is expressed. Unless you adopt a definition of "algorithm" that is so strict as to be useless except to an academic. #2: How important efficiency is depends on what you're writing. If you're working on time-critical code, it's very important, but if you're working on an application where most of the program's time will be spent waiting for the user to type in some input, a few hundred microseconds isn't anything to worry about. #3: A good optimizing compiler wouldn't do a compare/branch. It might set the flag, then notice that the next thing done is to test it, so it would blow off the test and just branch to wherever the "continue" statement was going to branch anyway. An even better optimizing compiler would then figure out that the flag is never actually tested, so it would just get rid of it. #4: Programmers don't always get to choose which language they use. #5: In this thread, we're arguing about readability and maintainability. If you have a situation where every nanosecond is critical, fine, but most of us are willing to give up a few nanoseconds in order to save time debugging and maintaining programs. If you've ever written a subroutine that was called at only one point in the rest of the program, instead of coding it inline so that you can avoid an unnecessary procedure call with all the stack pushes and pops, then certainly you have to admit that readability is worth sacrificing a couple machine cycles for, sometimes. > I'm not trying to start a language war - I'm pointing out that gotos > and the implicit goto forms (break, continue, etc) are a tool of the > language. They wouldn't be there if you NEVER needed them. There are lots of language constructs that aren't really "needed". And there are plenty of cases where an individual programmer, or a programming department, adopts a policy of avoiding a particular construct, which is fine as long as the prohibition isn't 100% absolute. A long time ago, I programmed in COBOL, and most of the programmers around me agreed that the ALTER statement was just a bad idea and shouldn't be used. I'll bet few would disagree with such a policy. -- Adam -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum