views:

461

answers:

6

From the preface of the second edition of Kernighan and Ritchie's "The C Programming Language":

As before, all examples have been tested directly from the text, which is in machine-readable form.

That quote threw me for a loop. What exactly does it mean? Was the original manuscript written as a literate program? My first thought was that this book, published in 1988 (original, first edition in 1978) predates literate programming, but now I'm not so sure.

Can anybody shed some light on this?

+6  A: 

I think they're saying that the book's text is available in some electronic form (who knows, maybe it was set using troff or something like that), and therefore they could easily extract the example code from it without having to type it in again a second time (which would possibly have resulted in code errors that were not actually in the book).


P.S.: I checked up on the history of troff (link goes to the Wikipedia article). As it turns out, Brian Kernighan was responsible for re-writing this old utility as a C program. It wouldn't surprise me if they'd have ended up using it for their own book...

stakx
Or worse: it could have have resulted in a code error in the book not being noticed when copying it. It's easy to see what you want to see instead of what is actually there.
Mark Byers
+2  A: 

I think it means that the book was prepared on a computer, which was unusual at the time of writing, so the text of the book and the example programs are machine-readable. Most books of that era were still typeset traditionally (i.e. hot metal).

Paul R
I'm not an expert on printing, but I don't think so: only newspapers were still using traditional "moveable type" typesetting in the 1980s.
Kinopiko
@Kinopiko: the first edition was published in 1978. Note that the preface says "As before..."
Paul R
I don't think printing technology suddenly changed between 1978 and 1980.
Kinopiko
@Kinopiko: Read up on the history of Linotypes and phototypesetting if you're interested: http://en.wikipedia.org/wiki/Linotype_machine and http://en.wikipedia.org/wiki/Phototypesetting.
Paul R
As I said I'm not an expert, but some of my relatives worked in the printing industry at that time. As I remember, typesetting was mostly being done by something they called IBM typesetters. I had a look at that article but didn't see mention of it.
Kinopiko
+2  A: 

I think that it just means that they typed it all up on a computer (which was a relatively novel thing for the time) and tested the examples by compiling them. Thus indicating there shouldn't be any errors in the example source code due to typos. I don't think it's a reference to literate programming.

Andrew Medico
+24  A: 

Kernighan and Ritchie produced the book using troff (which is a text-processing program like tex, not a wysiwig editor like word or openoffice) and a whole cast of supporting tools. Each programming example would have existed as the original C file, eg, ex1.c, which they could compile and test. That source file would be converted to a troff formatted version for typesetting, also by an automated tool. So, they could easily guarantee that the typeset program in the book was identical to the tested actual program.

As for literate programming, The C Programming Language predated the concept as defined by Knuth, but there are some broad similarities. Knuth's notion was more about a way to write a complete program together with its internal documentation.

Dale Hagglund
+2  A: 

The original book was prepared using troff, which is a flat-text file format with markup.

In a troff source file it is very easy to search for source code lines, yank them out to other files, and then compile them. If they used a 'source' directive for the source code lines, then each source example would have been in a separate file, in which case nothing would have had to be done to test them other than compile them.

KCCole
+5  A: 
Jörg W Mittag