[pisa-src] Re: r1765 - trunk/pisacd/cdservers.c

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Wed, 25 Nov 2009 11:07:55 +0100

On Wed, Nov 25, 2009 at 09:29:11AM +0100, Tobias Heer wrote:

> Ain't there a better way to do error handling here? I never really liked
> the goto jumps in HIPL but this kind of takes it to the extreme. I guess
> one could put all of these into one big if statement but that wouldn't
> make it much nicer either.

Whats weird in HIPL is not the goto but the fact that it is wrapped in a
macro. The problem with many points of failure in a function is, that each
path needs to clean up. Doing that with multiple ifs leads to duplicate clean
up code. Using goto for failure paths is a quite common concept, nothing that
HIPL invented. Goto itself isn't bad style IMO, just abusing it excessively.

To answer your question: No, I don't see an elegant way for error handling
without having duplicate or unreadable code. If someone does, I'm listening...

> In addition I really don't like the omission of braces for one-line if
> statements. This is quite error-prone, especially if people who have not
> written the code continue to work with it. I kon it is syntactically
> correct and it is slightly shorter but it is often the source of errors
> that are hard to find.

I'm kind of surprised that you notice this right now. It has been used in PISA
for nearly two years. The coding guideline document does not specify any
indent style that should be used. Since this has led to a big mess in the
past, I tried to motivate other coders to use K&R style [1]. What you're
suggesting is the 1TBS variant. You could write that down in the coding style
document and assign a HiWi to reformat the entire project, much like Diego is
currently whacking tabs.

[1] http://en.wikipedia.org/wiki/Indent_style#K.26R_style

-- 
Thomas Jansen, "Mithi" --- mithi@xxxxxxxxx
GPG 9D5C682B, feel free to sign or encrypt your mail

Other related posts: