Re: Why?? (prog question)

看板FB_chat作者時間17年前 (2009/04/06 11:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串6/23 (看更多)
(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輎tsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht M榀- chen, HRB 125758, Gesch輎tsf梶rer: 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. _______________________________________________ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to "freebsd-chat-unsubscribe@freebsd.org"
文章代碼(AID): #19sN6h00 (FB_chat)
討論串 (同標題文章)
文章代碼(AID): #19sN6h00 (FB_chat)