Path: utzoo!attcan!uunet!husc6!uwvax!rutgers!aramis.rutgers.edu!webber
From: webber@aramis.rutgers.edu (Bob Webber)
Newsgroups: comp.misc
Subject: Re: Basics of Program Design
Message-ID: 
Date: 23 Jun 88 02:48:59 GMT
References: <901@td2cad.intel.com> <3061@rpp386.UUCP>
Distribution: na
Organization: Rutgers Univ., New Brunswick, N.J.
Lines: 48

In article <3061@rpp386.UUCP>, jfh@rpp386.UUCP (John F. Haugh II) writes:
> ...
> yes, colleges and universities don't seem to big on useful information.
> a friend in college was charged with writing a string length function
> in C for a compiler writing class so he chose the `elegant' solution.
> 
> strlen (s)
> char	*s;
> {
> 	if (*s)
> 		return (strlen (s + 1) + 1);
> 	else
> 		return (0);
> }
> 
> not such a smart move.  always consider the cost of your algorithm.

A perfectly fine algorithm.  Any decent compiler would remove the tail
recursion.  I suppose one could do a little loop unrolling, but on
cpu's with instruction caches that is not always a big win.  Also it
is not clear that strlen would be heavily used (certainly it was never
a bottleneck in any of the compilers I wrote).  Of course, it would
have been nice if he could have psychically reached into the C
libraries and invoked the standard strlen function.  [Anyway it is a
much smarter move than declaring a function called ``write'' to handle
the write statement in the source language.]

>...
> worst mistake is to write code to soon.  code once writen becomes
> engraved in stone.  always be ready to throw the whole mess away and

Even more important, sometimes when you think long enough about a problem
it just goes away.

> start again.  there is a fantastic text, "The Mythical Man-Month -
> Essays in Software Engineering" which is a must read.  go buy it and
> read it fifty or a hundred times.

For sure and it is still available in print as a trade paperback.
Brooks wrote a note in IEEE Software Engineering not too long ago
saying how every time someone comes up to him and tells him how useful
his book is and how true to life the examples -- he shudders.
Apparently he had hoped things would get better.

------- BOB (webber@athos.rutgers.edu ; rutgers!athos.rutgers.edu!webber)

p.s., your description of how to ``actually write'' code looked fine to
me (I bet that makes you nervous).