[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: in defense of C

/* Written  1:35 pm  Mar  1, 1990 by gjc@mitech.COM in uicbert.eecs.uic.edu:comp.lang.scheme */
/* ---------- "in defense of C" ---------- */
In defense of C?
(Or an apology for small extensible languages with minimal overhead
 and minimal required runtime libraries).

The key here is the phrase "equivalent program in Pascal" coupled
with the extremely important suggestion I made, which is that C
could be used like you use lisp.

You say C has no array bounds checking. (In a way, big deal,
certainly the Lispmachines had extremely good low-level checking
of that nature, but it didn't keep the software or user from
being able to "... let machines crash or behave strangely" as Steele puts it).

It is so easy to build up error-checking routines from
non-error-checking primitives. Is that not what we do in lisp? (Maybe
we only *used* to do it, a lost art?) Here are some declarations from
some code I use every day:

struct bitarray
{long width; long height; char *data;};

int bitaref(struct bitarray *,int,int);

void bitaset(struct bitarray *,int,int,int);

struct bitarray *cons_bitarray(long,long);

Now, with prototype-enforcement there is absolutely no way my program is
going to crash or behave badly if I use these three guys, cons_bitarray,
bitaref and bitaset. 

The prototype-enforcement makes sure I'm not calling these on data
that are not bit arrays and integers. My C-compiler can inline these
and remove redundant error checking in many case.

I claim: A good engineer can generate a much richer and more useful set of
subroutines of this nature than found in ANY LANGUAGE DESIGNED BY COMMITTEE.

... especially compared to those those languages who's references manuals
start overflowing into multiple volumes!

On the subject of I/O primitives. "Gets" is one of those line-at-a-time
(what I called mainframe-style) procedures. Not what I had in mind (also,
not really what you should be calling primitive). Better to think in terms
of  getc and putc, or read and write, or XGetNextEvent.


p.s. "... let machines crash or behave strangely", personally *no* I
don't use the Macintosh and try to avoid writing Unix kernel code.
/* End of text from uicbert.eecs.uic.edu:comp.lang.scheme */