Article View: comp.std.c
Article #3394Re: GOTO single exit point (was: Re: How to eliminate GOTO?)
From: Peter Seebach
Date: Sat, 02 Sep 1995 07:48
Date: Sat, 02 Sep 1995 07:48
53 lines
2650 bytes
2650 bytes
[shouldn't this be in comp.lang.c[.moderated]?]
In article <4258ak$cj7@news0.rain.rg.net>, Paul Long <plong@perf.com> wrote:
>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.
That's not a readability problem. Consider:
list *
long_list_function(list *lp) {
if (!lp)
return NULL;
...
}
is better, by far, than skipping that return and littering the function
with redundant tests for lp. It's also better than an if (lp) {} around
the whole function; why waste an indentation level that communicates
nothing?
My respect for _Code Complete_ has just dropped a notch.
>Maybe you misunderstood me. I am _not_ proposing that gotos are a reasonable
>alternative to multiple return statements. Both are bad and avoidable.
I don't think either is bad. Either can be used badly; so can addition.
>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."
Wow. Slippery-slope strikes again!
I don't buy it. Gotos don't creep. They don't infest. They're a *tool*.
Now, setjmp() longjmp() pairs creep and infest - but gotos are *by definition*
restricted to one function in C. Pretty limited creeping.
I dislike "coding standards" based on the assumption that I'm a moron without
the ability to judge, case-by-case, whether or not something is appropriate.
>We disagree.
Well, I disagree with you! Tag!
-s
--
Peter Seebach - seebs@solon.com || seebs@intran.xerox.com --
C/Unix proto-wizard -- C/Unix questions? Send mail for help. No, really!
Copyright 1995 Peter Seebach. Like my work? Send donations!
The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq
Technical Details
Message-ID:
<429280$emm@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<3vn1ht$kj8@martha.utk.edu> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge.com> <4258ak$cj7@news0.rain.rg.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: seebs@solutions.solon.com (Peter Seebach) Newsgroups: comp.std.c,comp.lang.c Subject: Re: GOTO single exit point (was: Re: How to eliminate GOTO?) Date: 2 Sep 1995 02:48:16 -0500 Organization: Usenet Fact Police (Undercover) Message-ID: <429280$emm@solutions.solon.com> References: <3vn1ht$kj8@martha.utk.edu> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge.com> <4258ak$cj7@news0.rain.rg.net> NNTP-Posting-Host: solutions.solon.com