Article View: comp.std.c
Article #3390Re: GOTO single exit point (was: Re: How to eliminate GOTO?)
From: Paul Long
Date: Thu, 31 Aug 1995 21:07
Date: Thu, 31 Aug 1995 21:07
44 lines
3058 bytes
3058 bytes
volpe@bart.crd.ge.com (Christopher R. Volpe) wrote: >In article <41t0sb$15e@news0.rain.rg.net>, Paul Long <plong@perf.com> writes: [snip] >>Besides the obvious readability problem, > >Do you mean the readability problems associated with goto statements that >obfuscate what would otherwise be a simple return? Or do you mean the >readability problems associated with nesting the main body of a function >inside several else-clauses that check for terminate-now conditions? I mean the readability problem that Steve McConnell describes in _Code Complete_: "It's harder to understand a routine if, reading it at the bottom, you're unaware of the possibility that it returned somewhere above." IOW, the logic within a routine no longer flows completely from top to bottom. [snip] >Gotos are dangerous and abusable enough that I would rather take a >chance on having to make a one-time change to remove multiple return >statements, than indiscriminately inject gotos in all my code where I would >otherwise use a non-abusable return statement. Maybe you misunderstood me. I am _not_ proposing that gotos are a reasonable alternative to multiple return statements. Both are bad and avoidable. >I'm not saying there aren't good uses of a goto. There are. But when you see a >goto statment, bells and whistles should go off in your head, because it's a >source of potential trouble. The more one becomes desensitized to goto >statements by frequent use, the less likely one is to notice bad uses, IMO. I agree. Since I still have the book open, here's another quote from _Code Complete_: "Even if gotos aren't confusing when used carefully, once gotos are introduced, they spread through the code like termites through a rotting house. If any gotos are allowed, the bad creep in with the good, so it's better not to allow any of them." >Therefore, I use gotos only when the alternative is less readable. This is not >true for the general case of multiple return points. We disagree. -- Paul Long 45:29:14N 122:48:09W plong@perf.com http://www.teleport.com/~pciwww/ "Wagging head and tail, the red-tailed fish, unsupported, turns around."
Technical Details
Message-ID:
<4258ak$cj7@news0.rain.rg.net>Path:
arc1-ca.pugleaf.net!newsfeed.internetmci.com!psgrain!rainrgnews0!usenetReferences:
<3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <41glno$3a0@caip.rutgers.edu> <41iebe$kec@news0.rain.rg.net> <41pm80$skp@inferno.mpx.com.au> <DE02nC.B58@eskimo.com> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsfeed.internetmci.com!psgrain!rainrgnews0!usenet From: Paul Long <plong@perf.com> Newsgroups: comp.std.c,comp.lang.c Subject: Re: GOTO single exit point (was: Re: How to eliminate GOTO?) Date: 31 Aug 1995 21:07:32 GMT Organization: Performance Computing Incorporated Message-ID: <4258ak$cj7@news0.rain.rg.net> References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <41glno$3a0@caip.rutgers.edu> <41iebe$kec@news0.rain.rg.net> <41pm80$skp@inferno.mpx.com.au> <DE02nC.B58@eskimo.com> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge.com> NNTP-Posting-Host: yosemite.perf.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.1 sun4c) X-URL: news:DE6G2z.JJD@crdnns.crd.ge.com