Alexander Lamaison wrote:
> > Would anyone veto changes that reduce mindless code duplication such
> > as above with the use of forward gotos to the end of functions?
> Rather than gotos, how about a helper function e.g.:
A function brings a new scope which may not always work. goto is not
a bad thing if used right. I think forward gotos for error handling
is an excellent way to keep code clean, coherent and short:
/* main stuff */
> Or am I missing the need for gotos (not got the code in front of me)?
Cleaning up ptr in the above example is the point. Instead of
duplicating cleanup code in every single error handling branch within
main stuff, all cleanup code is in one single location.
That way, there is much less code overall and writing error handling
is greatly simplified, which means more likely to be done and much
more likely to not introduce new bugs because of overlooked cleanup.
Received on 2010-01-21