> 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've never fully subscribed to that generalisation. But the arguments made in its favour have made me think about the necessity of several constructs use in code. In general I have found goto is largely useless. Where its most tempting is in badly designed code. typedef has its place in C particularly for portability issues, but that is vastly reduced in C++. I've only seen the event/callback function-pointers as a required use for it nowadays. That only because none has shown me a better way to do function pointers than the way squid currently does them. Amos