Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!henry
From: henry@utzoo.UUCP (Henry Spencer)
Newsgroups: comp.lang.c
Subject: Re: goto's in C: an opinion...
Message-ID: <8318@utzoo.UUCP>
Date: Sat, 18-Jul-87 21:07:26 EDT
Article-I.D.: utzoo.8318
Posted: Sat Jul 18 21:07:26 1987
Date-Received: Sat, 18-Jul-87 21:07:26 EDT
References: <3289@bigburd.PRC.Unisys.COM>
Organization: U of Toronto Zoology
Lines: 29
Keywords: C, goto, style

> My point is that 99% of the time I see a goto in a C program, it is
> not there for any good reason...

The rule I follow is that the desire to use a goto is a symptom of poorly-
organized code, and in particular is a sign that code has not been split
up into functions as it should be.  Barring emergencies, the right response
is to step back a bit and consider whether the code needs reorganizing.
In twelve years of C programming, my experience has been that the answer
*invariably* is "yes".

I feel roughly the same way about "continue", by the way, although it's not
as bad and I do use it occasionally.

People who say "but I can't call functions, I can't afford the overhead"
usually have no idea where the time in their program really is going, and
thus have no rational basis for that statement.  There may indeed be a few
places where call overhead is unacceptable, but the time to do something
about that is *after* the program is working and can be profiled.  Then,
and only then, it *may* be appropriate to revise a few small pieces of the
code to be faster but a bit less clean.  Inverting the order of these steps
generally just makes an unnecessary mess.  Human intuition simply is not a
reliable guide to the location of the real bottlenecks.

See also Collyer&Spencer, "News Need Not Be Slow", Washington 1987 Usenix
conference proceedings, for more discussion of these issues in the context
of improving news performance by 1.5 orders of magnitude.
-- 
Support sustained spaceflight: fight |  Henry Spencer @ U of Toronto Zoology
the soi-disant "Planetary Society"!  | {allegra,ihnp4,decvax,utai}!utzoo!henry