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: 1014db,4c42ac518eba0bbe X-Google-Attributes: gid1014db,public X-Google-Thread: 109fba,4c42ac518eba0bbe X-Google-Attributes: gid109fba,public From: Stephan Wilms Subject: Re: Coding for Obscurity Date: 1997/11/20 Message-ID: <34741AAF.1C7@CWA.de>#1/1 X-Deja-AN: 290958154 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> Organization: CWA GmbH Reply-To: Stephan.Wilms@CWA.de Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-11-20T00:00:00+00:00 List-Id: 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; } Stephan (initiator of the campaign against grumpiness in c.l.c)