Date: Wed, 1 Apr 2009 15:50:49 +0200 (CEST) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-chat@FreeBSD.ORG, will.rutherdale@utoronto.ca Subject: Re: Why?? (prog question) Message-ID: <200904011350.n31DonkS063174@lurza.secnetix.de> In-Reply-To: <49D359D4.60103@utoronto.ca>
next in thread | previous in thread | raw e-mail | index | archive | help
(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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904011350.n31DonkS063174>