From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4c42ac518eba0bbe X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,4c42ac518eba0bbe X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,4c42ac518eba0bbe X-Google-Attributes: gid1014db,public From: Alex Krol Subject: Re: Coding for Obscurity Date: 1997/11/23 Message-ID: <34788101.7367@scitex.com>#1/1 X-Deja-AN: 291766535 References: <343fbb5a.0@news.iprolink.ch> <34466EB4.3381@dynamite.com.au> <6275dt$agm$3@news.on> <344BCED0.2D51@dynamite.com.au> <62tpap$7gh$1@darla.visi.com> <3470EF6E.F74@lysator.liu.se> <64qsf0$ccc@dfw-ixnews11.ix.netcom.com> <3474BF28.2F9F@dynamite.com.au> <34741AAF.1C7@CWA.de> Organization: Scitex_Corporation_LTD. Reply-To: Alex_Krol@scitex.com Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-11-23T00:00:00+00:00 List-Id: Stephan Wilms wrote: > > Alan E & Carmel J Brain wrote: > > > > firewind wrote: > > > > > I find myself using a construct like this a lot recently (snipped directly > > > from code I'm working on right now): > > > > > > if(!to && !(to = malloc(sizeof *to)))) return(NULL); > > > > > > The > > > if(foo() || bar()) > > > > > > construct may seem obfuscated and weird to you, it is the way the logic of > > > some people's minds work. > > > > No further evidence, I rest my case. > > > > Would anyone in comp.lang.c like to comment? > > Yes, I'll volunteer a little comment: code like that has a lot of > disadvantages: it is obfuscated (it's only the author wh thinks that > the code is readable) and it's hard to debug and maintain. It sure > wouldn't pass through my code inspection. > > To explain: readability of code is not targeted at the author of the > code or maybe his office pal, it is targeted at someone having to > read and understand a whole big package of source code, to make > some important modification or to find a bug a year after the software > has been written and archived. The author might not even be available > at this moment. Even the smallest effort helps a lot. > > In detail: I would reqrite the first example like this: > > /* Sensible comment about what get's allocated. */ > if ( to == NULL ) > { > to = malloc( sizeof *to); > if ( to == NULL ) return NULL; > } Of course, style matters are extremely personal, but, IMHO, there is nothing unreadable in the first example (except unmatched parenthesis :-)). I agree that readability of code is not targeted at the author himself, but must it be targeted at a newbie unfamiliar with C idiomas? Comments, though are advisable in any case. Regards, Alex Krol