[comp.lang.misc] Software reuse and WEB.

kbb@nancy (Karl Berry.) (06/23/87)

The recent note on reuse of software made me think of the recent columns
in Communications of ACM on WEB. (The column was Jon Bentley's
Programming Pearls. WEB is a language invented by Don Knuth.)

In my own programming, I try to write using abstract data types
and all that. Although my interface designs always seem reasonable at
the time, and always work fine for that program, when I try to use it in
a new program, I seem to have always left something out (because it
wasn't needed in the first program) or have the wrong functionality, or
something. 

The article posted here (sorry, I forget the author) said, among other
things, that maybe abstract data types are too low a level to aim for in
reuse, and that we should try to reuse even higher level chunks of code.

Maybe we should be trying to reuse lower level chunks of code. TeX and
Metafont (Knuth's program, written in WEB) aren't written in the
abstract data type style (as David Gries suggested, primarily because
Gries thought such typles make it easy to build up libraries) in one of those
Programming Pearls columns) but that didn't hinder Knuth from re-using
large amounts code from TeX (the current version of which was written in
1982) to Metafont (in 1985). My own experiences with WEB code, on a
smaller scale, are similar: it's easier to copy not abstract data types,
but just pieces of code.

I know people do have libraries of abstract data types that get used by
lots of people. The Eiffel implementors (Bertrand Meyer, et. al.) claim
they have one. The Ada people claim they have one. The C people claim
they have one. And on and on. But maybe we should look at both higher
AND lower levels than abstract data types for reusing code.

Or maybe we should just always write from scratch. Duncan Hines and
homemade don't compare in the kitchen.

Karl. kbb@cs.brown.edu {decvax,ihnp4,allegra,...}!brunix!kbb

russ@anduk.UUCP (russ) (06/29/87)

It's important to distinguish between (parts of) things that can be 
reused and things that are designed in order to facilitate reusability.

In article <16556@brunix.UUCP> kbb@nancy (Karl Berry.) writes:
>The recent note on reuse of software made me think of the recent columns
>in Communications of ACM on WEB.  [...]

Background: See May 1986 and in particular June 1986 CACM Programming Pearls.

Don Knuth was invited to solve a simple problem using web.
  ... a user should be able to find the 100 most frequent words in a
  twenty-page technical paper ... without undue emotional trauma.

The article listed Knuth's solution, then the review you mention, by Doug
McIlroy, who also gives his own 6-line solution to the problem.

> Maybe we should be trying to reuse lower level chunks of code.
> [...]
> My own experiences with WEB code, on a
> smaller scale, are similar: it's easier to copy not abstract data types,
> but just pieces of code.

easier than what? Pascal?  I find it easy, but prefer not to have to do so.
Using routines from libraries is almost always more robust and easier.  And
using unix utilities usually leads to a working prototype very quickly.

The Pearls review concludes 
	Knuth has shown us here how to program intelligently,
	but not wisely.  I buy the discipline.  I do not
	buy the result. He has fashioned a sort of industrial-
	strength Faberge egg--intricate, wonderfully worked,
	refined beyond all ordinary desires, a museum piece
	from the start.

Reusing code is a different issue than Abstract Data Types and Object Oriented
Programming.  In the former case, an understanding of the implementation of
the code is needed; Web may facilitate this.  But in the latter, no knowledge
of the contents of the black box is needed.

It's like the difference between copying the _code_ for the sort routine
each time you want to sort things, or (the Object approach) simply calling
(or "applying") the sort routine.

	"A wise engineering solution would produce--or, better,
	 exploit--reusable parts" [July 1986 CACM p.480]

> I know people do have libraries of abstract data types that get used by
> lots of people.  [...] But maybe we should look at both higher AND lower
> levels than abstract data types for reusing code.

Clearly.  People who only use things on a Dogmatic Basis
	X is an abstract data type <----> I can reuse X
miss out on a lot of good stuff.  This is as true in Computing as elsewhere.

Common idioms (i.e. reused bits) in C are things like
	while ((c = getchar()) != EOF) {	/* process the entire file */
		...				/* a charcter at a time */
	}
and
	for (;;) {	/* loop forever or until an exception condition */
		...
	}
and
	for (p = src, q = dest; *q++ = *p++; ) ;
		/* copy an array object by object */

But I wouldn't bother documenting them.  They're known to all experienced
C programmers, and are in a sense part of the language, just as
	Don't cross your bridges til you come to them
is part of the English language.  You don't really know English until you
can cope with a working subset of idioms and metaphors.

Reusing lumps of code is often dangerous... the better the documentation,
the more likely you are to forget to go over it with a fine comb looking
for that tiny undocumented assumption...  This is one of the strong points
of the Object Oriented Camp, that side-effects of routines are either non-
existant or well understood.

It's important to distinguish between (parts of) things that can be 
reused and things that are designed in order to facilitate reusability.

Russell
-- 
Russell Quin, Unixsys UK Ltd, The Genesis Centre, Birchwood, Warrington WA3 7BH
{utai,ukc!mucs}!anduk!russ [please don't try to use mucs!anduk!utai!...]
+44 925 827834, or 0925 828181 from UK; Telex 946240 CWEASY G Ref. 19021810