Date: Wed, 01 Apr 2009 08:11:00 -0400 From: William Gordon Rutherdale <will.rutherdale@utoronto.ca> To: freebsd-questions@FreeBSD.ORG Subject: Re: Why?? (prog question) Message-ID: <49D359D4.60103@utoronto.ca> In-Reply-To: <200904010839.n318dkuJ050633@lurza.secnetix.de> References: <200904010839.n318dkuJ050633@lurza.secnetix.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Oliver Fromme wrote
> Of course this is purely a matter of taste and personal
> preference. My preference is similar to yours, but my
> main reasoon is to save space. I think it is a ridiculous
> waste of space if every third line consisted only of a
> sole brace (opening or closing). To my eye, such lines
> that are almost empty break the natural structure of a
> piece of source code. I insert empty lines quite often
> in order to group source lines logically, but brace lines
> break that grouping visually.
>
>
There is a very logical reason in C for wanting to put the opening brace
of an 'if' statement on a separate line: preprocessor statements.
Many editors, including vi / vim, and no doubt emacs, have a brace
matching facility. If I put the cursor over a closing brace, say, and
hit the % key, it puts me onto the matching opening brace. However in
this scenario:
int foo( int x )
{
#ifdef SCENARIO_A
if ( x<3 ) {
#else
if ( x<2 ) {
#endif
// . . .
}
// . . .
}
matching the closing brace of foo() will fail, as the number of braces
no longer matches.
Putting the opening brace of the 'if' on another line solves this problem.
-Will
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49D359D4.60103>
