Re: two xasserts in squid3

From: Robert Collins <robertc@dont-contact.us>
Date: Mon, 11 Feb 2008 14:06:43 +1100

On Mon, 2008-02-11 at 11:49 +0900, Adrian Chadd wrote:
> On Mon, Feb 11, 2008, Amos Jeffries wrote:
>
> > > I end up with -one- exit location in the function and I don't have to
> > > bum around using extra functions or massively nested conditional
> > > constructs to achieve it. In fact, I've used goto in a few places to
> > > tidy up the code..
> >
> > If you need to use it to clean up a single function. It's an obvious sign
> > that the function is too complicated. In 10 years of writing complicated
> > code I have yet to see a single place where it is actually required.
>
> Required? No. Useful? Yes.
>
> Too often I've seen people push the "cleanup" stuff into another function,
> thinking that bit of refactoring was a good idea. Thing is, if they didn't
> document that the function is private just for another function, some other
> coder will come along later, see the function, and think its fine for them
> to use (solving their immediate problem.) This leads to badness in the
> future.
>
> It took me quite a while to get over the "goto is evil, never ever use it"
> koolaid. But then, in C++, you should be using exceptions, not weird
> flow control tricks. :)

I quite like the very structured way of using goto: that the linux
kernel encourages. Its certainly cleaner the way they do it than reused
helper functions - you need a bazjillion little functions to clean up
nested resources properly, and you end up with two sets: a tonne of
little 'call X cleanup, then chain to Y the remaining things to cleanup'
functions. And secondly, all the actual X cleanup functions.

-Rob

-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.

Received on Sun Feb 10 2008 - 20:06:46 MST

This archive was generated by hypermail pre-2.1.9 : Sat Mar 01 2008 - 12:00:09 MST