🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3386

GOTO single exit point (was: Re: How to eliminate GOTO?)

#3386
From: Paul Long
Date: Mon, 28 Aug 1995 18:11
20 lines
1873 bytes
mag@eskimo.com (mag) wrote:
>One of the excellent uses of goto is to force a single exit point for a function. 
[snip:code example with goto common return]

Your example illustrates that multiple return statements are second cousin to
goto statements. I _never_ use more than one return statement in a function,
and I _almost never_ use a goto (once every few years). 

Besides the obvious readability problem, a practical problem occurs during
maintenance when one wants to do something immediately before the function
returns. If there are embedded return statements, one has to either duplicate
the code before each return statement or first untangle the code so that it has
one return statement. Both solutions increase the likelihood of introducing
another error--a "bad fix." The programmer cannot know when the function is
first written whether this will need to be done sometime in the future.

-- 
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: <41t0sb$15e@news0.rain.rg.net>
Path: arc1-ca.pugleaf.net!usenet.eel.ufl.edu!pacifier!rainrgnews0!usenet
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>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!usenet.eel.ufl.edu!pacifier!rainrgnews0!usenet
From: Paul Long <plong@perf.com>
Newsgroups: comp.std.c,comp.lang.c
Subject: GOTO single exit point (was: Re: How to eliminate GOTO?)
Date: 28 Aug 1995 18:11:23 GMT
Organization: Performance Computing Incorporated
Message-ID: <41t0sb$15e@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>
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:DE02nC.B58@eskimo.com