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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,4c42ac518eba0bbe X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,4c42ac518eba0bbe X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,4c42ac518eba0bbe X-Google-Attributes: gid109fba,public From: "Jim Johnson" Subject: Re: Coding for Obscurity Date: 1997/11/24 Message-ID: <01bcf8fc$e918e0a0$0644a3cd@jimj.jumpmusic.com>#1/1 X-Deja-AN: 292231208 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> <34788101.7367@scitex.com> Organization: Jump! Music Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-11-24T00:00:00+00:00 List-Id: > 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? Yes, it must; because in most situations, that is who the maintenance programmers are. "unfamiliar with C idioms" could be any of us. There are so many ways to write C code, there is no way to predict which ones your audience will have used. (Personally, I never use ?: conditionals; I always have to think it through when I see them.) Jim Johnson Alex Krol wrote in article <34788101.7367@scitex.com>... > 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 >