Subject: Re: goto netbsd
To: Christos Zoulas <christos@zoulas.com>
From: David Maxwell <david@vex.net>
List: netbsd-advocacy
Date: 09/04/2002 17:11:01
On Wed, Sep 04, 2002 at 09:03:06PM +0000, Christos Zoulas wrote:
> In article <Pine.LNX.4.43.0209041233020.3105-100000@pilchuck.reedmedia.net>,
> Jeremy C. Reed <reed@reedmedia.net> wrote:
> >On Wed, 4 Sep 2002 collver1@attbi.com wrote:
> >
> >> # from NetBSD 1.5.3
> >>
> >> $ find /usr/src -name '*.c' | xargs grep goto | wc -l
> >>    27381
> >
> >And your point is?
> >
> >Do you have specific examples why the gotos are good or bad? (And do you
> >have patches to improve as needed?)
> >
> >And why is this on the advocacy mailing list?
> >
> 
> I expect most of these are in the kernel where goto use is encouraged
> to avoid code duplication in the error cleanup paths of various
> functions/syscalls.

Well, a full 1/3rd seem to be matches against variable and function
names or comments. Of the remaining 2/3rds, here are the most popular
labels (50 or more references).

The topmost labels certainly look like 'good' uses of goto, while some
of the ones at the bottom of the list are questionable...

2440 out
2148 bad
2141 err
1431 end
1373 done
1092 fail
 493 error
 489 again
 282 loop
 247 next
 213 found
 208 cleanup
 205 ret
 156 retry
 146 abort
 128 recurse
 118 trunc
 109 Cleanup
 106 failure
 101 restart
  97 usage
  93 lose
  86 nosideret
  81 ok
  79 out2
  77 top
  75 skipline
  71 exit
  68 finish
  65 drop
  64 common2
  64 skip
  63 binop
  63 dopanic
  58 freeit
  58 yyerrlab
  54 reset
  54 yydefault
  54 yynewstate
  52 invalid
  51 bad2
  51 out1
  51 release
  50 immediate


The last few were:

   1 usecurrent
   1 usevc
   1 uuuuglyy
   1 uwait
   1 v4chk
   1 v6tempfail
   1 valuable
   1 verylittleleft
   1 vol1
   1 wake
   1 walk
   1 ws
   1 xenum
   1 xxx
   1 zx312
   1 zzz
   1 zzzz

Naturally, the entire source tree includes many sources not developed by
the NetBSD project, and eliminating gotos has never been a top priority.
:-)

-- 
David Maxwell, david@vex.net|david@maxwell.net -->
Any sufficiently advanced Common Sense will seem like magic... 
					      - me