comp.lang.ada
 help / color / mirror / Atom feed
From: "Jos A. Horsmeier" <jos@and.nl>
Subject: Re: Coding for Obscurity
Date: 1997/11/21
Date: 1997-11-21T00:00:00+00:00	[thread overview]
Message-ID: <34754E5E.7498D9F@and.nl> (raw)
In-Reply-To: 34741AAF.1C7@CWA.de


Stephan Wilms wrote:
> Alan E & Carmel J Brain wrote:
> > firewind wrote:

> > > 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;
>   }

Although we're talking about style and taste here (which can't be
discussed IMHO), I jumped into (another thread of) this discussion
because I recognized the construct above. Something like 15 years
ago our team went OO (and gaga too, but that's an entirely different
story ;-) C++ was hardly concipiated yet, so we turned to SmallTalk
and borrowed (read 'stole') some features from that language. We were
still dealing with plain old C though ... 

We wanted to handle 'automatic or global' objects and 'dynamic objects'
(just
to borrow some terminology from C++) in C. Amongst other stuff we came 
up with the following macros:

#define NEW(x) ((x) && !((x)->dyn= NULL) || ((x)= malloc(sizeof *(x)))
&& ((x)->dyn= (x)))
#define OLD(x) free((x)->dyn)

(I'm typing this from the top of my head, so be gentle with me here)

An object was represented by a simple struct. One member of such a
struct 'dyn'
contained the address of the struct itself if it was allocated
dynamically, 
otherwise it would contain a NULL pointer. Given those macros we were
able 
to do things like:

	void foo() {

		obj_t	x;
		obj_t*	y= NULL;

		if (NEW(&x)) 
			/* init x; */

		if (NEW(y))
			/* init *y */

		/* do some useful stuff with x and y here */

		OLD(&x);
		OLD(&y);
	}

The NEW macro registered the fact that the memory of an object was
already there
if it were passed the address of an existing struct. The OLD macro would 
peek at the 'dyn' member and pass it to free (we were simply lucky that
free(NULL)
did what we wanted it to do in those days, but if you tell them
youngsters that,
they won't believe ya ;-)

I'm the one to blame for those macros. I just finished some boring
project using
RPG (I guess it was RPG2, but I don't recall exactly) and I did like
those tagged
statements, i.e.

	foo && bar

where 'bar' would only be executed if 'foo' were true (later RISC chips
even implemented
this nice little feature). Maybe my braincell was damaged by my former
RPG experience,
but I found (and still find) the logic behind this all quite readable.
So you're
at least partly right: 'it's the author who thinks that this is
readable'. But the
fun part of this all is, that our team found this construct (and the
accompanying
macros) quite readable too, I wasn't the only lunatic in town ...

I agree that such a construct shouldn't be written down just to inflate
your
ego, but a carefully constructed (or should I say 'crafted') expression
like
this can be highly readable for those who are at least familiar with it. 

But this notion leads to the question -- how qualified should software
maintaining
people be? If they're overqualified (and this very suitable for the
job), they
don't want this type of job (and vice versa is true too).

kind regards,

Jos aka jos@and.nl




  reply	other threads:[~1997-11-21  0:00 UTC|newest]

Thread overview: 147+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <343fbb5a.0@news.iprolink.ch>
1997-10-11  0:00 ` Programming language vote - results Gary L. Scott
1997-10-12  0:00   ` Jack Rudd
1997-10-13  0:00     ` Gary L. Scott
1997-10-13  0:00     ` safetran
1997-10-13  0:00       ` Jack Rudd
1997-10-14  0:00         ` Philip Brashear
1997-10-14  0:00           ` Gary L. Scott
1997-10-13  0:00       ` FRS DES
1997-10-13  0:00     ` Robert Munck
1997-10-13  0:00       ` Jack Rudd
1997-10-13  0:00       ` Gary L. Scott
     [not found]     ` <3442B745.5352@lmco.com>
1997-10-15  0:00       ` Gary L. Scott
1997-10-16  0:00       ` James Giles
1997-10-16  0:00         ` Andrew Haley
1997-10-13  0:00   ` Matthew Heaney
1997-10-14  0:00     ` Gary L. Scott
1997-10-13  0:00   ` Robert S. White
1997-10-13  0:00     ` Gary L. Scott
1997-10-13  0:00   ` David Ness
1997-10-14  0:00     ` Randy MacDonald
1997-10-14  0:00     ` Jan Karman
1997-10-15  0:00       ` Alan E & Carmel J Brain
1997-10-15  0:00         ` D'Arcy J.M. Cain
1997-10-15  0:00           ` FRS DES
1997-10-15  0:00           ` Mark Stephen
1997-10-17  0:00             ` Randy MacDonald
1997-10-16  0:00           ` Alan E & Carmel J Brain
1997-10-16  0:00             ` John Sullivan
1997-10-17  0:00               ` Randy MacDonald
1997-10-17  0:00               ` Alan E & Carmel J Brain
1997-10-17  0:00                 ` John Sullivan
1997-10-16  0:00             ` FRS DES
1997-10-17  0:00               ` Jerry van Dijk
1997-10-17  0:00             ` Randy MacDonald
1997-10-20  0:00               ` Alan E & Carmel J Brain
1997-10-20  0:00                 ` FRS DES
1997-10-21  0:00                   ` Alan E & Carmel J Brain
1997-10-20  0:00                 ` Lawrence Kirby
1997-10-20  0:00                   ` Kaz
1997-10-21  0:00                     ` Alan E & Carmel J Brain
1997-10-23  0:00                     ` Ada Readability (Re: Programming language vote - results) Ray Blaak
1997-10-21  0:00                   ` Programming language vote - results Alan E & Carmel J Brain
1997-10-21  0:00                 ` Randy MacDonald
1997-10-22  0:00                   ` Don Guinn
1997-10-29  0:00                     ` Randy MacDonald
     [not found]                     ` <01bce1bf$5c2baaa0$95b66bcf@dkelly.ark.com>
1997-10-29  0:00                       ` FRS DES
1997-10-29  0:00                       ` Don Guinn
1997-10-29  0:00                         ` Shmuel (Seymour J.) Metz
1997-10-31  0:00                         ` Documenting Code (was:Programming language vote - results) Alan E & Carmel J Brain
1997-10-30  0:00                           ` Charles Lin
1997-10-30  0:00                             ` James L. Ryan
1997-10-31  0:00                               ` Robert Bernecky
1997-10-31  0:00                             ` Robert Bernecky
1997-11-01  0:00                           ` Randy MacDonald
1997-11-01  0:00                             ` Robert Dewar
1997-11-03  0:00                               ` Jon S Anthony
1997-10-25  0:00                   ` Programming language vote - results Alan E & Carmel J Brain
1997-10-26  0:00                     ` functionality of Java (was Re: Programming language vote - results) Randy MacDonald
1997-10-23  0:00                 ` Programming language vote - results Jack Rudd
1997-10-25  0:00                   ` Alan E & Carmel J Brain
1997-10-25  0:00                     ` Kaz
1997-10-26  0:00                       ` FRS DES
1997-10-27  0:00                       ` Robert Bernecky
1997-10-27  0:00                         ` APL argument W. Wesley Groleau x4923
1997-10-28  0:00                           ` Randy MacDonald
1997-10-28  0:00                         ` Programming language vote - results Jan Karman
1997-10-28  0:00                           ` Robert Bernecky
1997-10-28  0:00                             ` James L. Ryan
1997-10-29  0:00                               ` Robert Bernecky
     [not found]                                 ` <bosworth-2910972044300001@access59.accsyst.com>
1997-10-30  0:00                                   ` Robert Bernecky
1997-10-30  0:00                                     ` James L. Ryan
1997-10-31  0:00                                       ` Robert Bernecky
1997-10-31  0:00                                         ` James L. Ryan
1997-10-29  0:00                     ` Jack Rudd
1997-10-25  0:00                 ` Peter Seebach
1997-11-18  0:00                   ` Ingemar Ragnemalm
1997-11-18  0:00                     ` Kevin Swan
1997-11-29  0:00                       ` Ingemar Ragnemalm
1998-09-10  0:00                         ` Steven Katz
1997-11-18  0:00                     ` Lawrence Kirby
1997-11-24  0:00                       ` Martin M Dowie
1997-11-25  0:00                         ` Mark Wilden
1997-11-25  0:00                           ` Martin M Dowie
1997-11-26  0:00                             ` Lawrence Kirby
1997-11-26  0:00                           ` FRS DES
1997-11-25  0:00                         ` Kaz Kylheku
1997-11-26  0:00                           ` Peter Seebach
1997-12-02  0:00                           ` ANDREAS LEITNER
1997-12-02  0:00                             ` Robert Dewar
1997-12-02  0:00                             ` Lawrence Kirby
1997-12-03  0:00                               ` Billy Chambless
1997-12-03  0:00                                 ` Robert Dewar
1997-12-05  0:00                             ` John Sullivan
1997-11-18  0:00                     ` firewind
1997-11-18  0:00                       ` Larry Elmore
1997-11-20  0:00                         ` firewind
1997-11-18  0:00                       ` Kevin Swan
1997-11-19  0:00                         ` Alan E & Carmel J Brain
1997-11-19  0:00                       ` Mike Smith
1997-11-19  0:00                         ` Matt
1997-11-20  0:00                         ` firewind
     [not found]                           ` <3474C71B.536B12F6@cgocable.net>
1997-11-21  0:00                             ` CVigue
1997-11-23  0:00                           ` Lawrence Kirby
1997-11-24  0:00                             ` FRS DES
1997-11-20  0:00                       ` Terry Richards
1997-11-20  0:00                         ` Andy Knight
1997-11-23  0:00                         ` Alex Krol
1997-11-25  0:00                         ` William Tanksley
1997-11-26  0:00                           ` Ron Natalie
1997-11-27  0:00                             ` William Tanksley
1997-11-27  0:00                               ` Lawrence Kirby
     [not found]                                 ` <65keij$mkd$1@nerd.apk.net>
1997-11-27  0:00                                   ` Kaz Kylheku
1997-11-28  0:00                               ` Shmuel (Seymour J.) Metz
1997-12-01  0:00                                 ` FRS DES
1997-11-20  0:00                       ` Coding for Obscurity Alan E & Carmel J Brain
1997-11-20  0:00                         ` firewind
1997-11-20  0:00                           ` Jos A. Horsmeier
1997-11-20  0:00                         ` Stephan Wilms
1997-11-21  0:00                           ` Jos A. Horsmeier [this message]
1997-11-23  0:00                           ` Alex Krol
1997-11-24  0:00                             ` Jim Johnson
1997-11-24  0:00                               ` Mark Wilden
1997-11-26  0:00                                 ` Robert S. White
1997-11-26  0:00                                   ` Mark Wilden
1997-11-26  0:00                                   ` Miguel Carrasquer Vidal
1997-12-01  0:00                                     ` ISONE
1997-12-01  0:00                                     ` ISONE
1997-11-26  0:00                                   ` Leon Jones
1997-11-26  0:00                                     ` Lawrence Kirby
1997-11-26  0:00                                     ` Ron Natalie
1997-11-27  0:00                                       ` Joerg Rodemann
1997-11-27  0:00                                   ` Richard A. O'Keefe
1997-11-23  0:00                           ` Al Christians
1997-11-24  0:00                           ` Richard A. O'Keefe
1997-11-24  0:00                             ` Samuel T. Harris
1997-11-24  0:00                               ` Jon S Anthony
1997-11-25  0:00                                 ` Samuel T. Harris
1997-11-24  0:00                             ` Matt
1997-11-24  0:00                               ` Ed Falis
1997-11-20  0:00                       ` Programming language vote - results Andy Knight
1997-11-20  0:00                         ` firewind
1997-11-19  0:00                     ` Peter Seebach
1997-11-19  0:00                     ` Alan E & Carmel J Brain
1997-10-16  0:00           ` Randy MacDonald
     [not found]           ` <01bcdad2$fa9fdf60$25a43a91@basil.omroep.nl>
1997-10-17  0:00             ` D'Arcy J.M. Cain
1997-10-17  0:00         ` Robert I. Eachus
1997-10-19  0:00 ` William Rapp
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox