From owner-freebsd-chat@FreeBSD.ORG Wed Apr 1 13:51:15 2009 Return-Path: Delivered-To: freebsd-chat@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2234B106566B for ; Wed, 1 Apr 2009 13:51:15 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 7E1E68FC08 for ; Wed, 1 Apr 2009 13:51:14 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id n31DonYS063175; Wed, 1 Apr 2009 15:51:13 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id n31DonkS063174; Wed, 1 Apr 2009 15:50:49 +0200 (CEST) (envelope-from olli) Date: Wed, 1 Apr 2009 15:50:49 +0200 (CEST) Message-Id: <200904011350.n31DonkS063174@lurza.secnetix.de> From: Oliver Fromme To: freebsd-chat@FreeBSD.ORG, will.rutherdale@utoronto.ca In-Reply-To: <49D359D4.60103@utoronto.ca> X-Newsgroups: list.freebsd-questions User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Wed, 01 Apr 2009 15:51:13 +0200 (CEST) Cc: Subject: Re: Why?? (prog question) X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-chat@FreeBSD.ORG, will.rutherdale@utoronto.ca List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2009 13:51:15 -0000 (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.