Why?? (prog question)
Oliver Fromme
olli at lurza.secnetix.de
Wed Apr 1 06:51:15 PDT 2009
(Note: Redirected to -chat.)
William Gordon Rutherdale wrote:
> 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.
The preprocessor is one of the biggest mistakes in the design
of the C language. This is one of the reasons why. :-)
> int foo( int x )
> {
> #ifdef SCENARIO_A
> if ( x<3 ) {
> #else
> if ( x<2 ) {
> #endif
> // . . .
> }
> // . . .
> }
Personally I think that code intermixed with #ifdef stuff
looks butt ugly and is difficult to read, no matter where
you put the braces.
I would rather try to refactor the code, so the #if stuff
is separate and doesn't rupture the function content, like
this:
#ifdef SCENARIO_A
# define FOO_CONDITION (x < 3)
#else
# define FOO_CONDITION (x < 2)
#endif
int foo( int x )
{
if (FOO_CONDITION) {
// . . .
}
// . . .
}
Problem solved, and the whole thing is much more readable.
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
"C is quirky, flawed, and an enormous success."
-- Dennis M. Ritchie.
More information about the freebsd-chat
mailing list