[Tutor] little something ... develops towards Stanford Graphbase / programs as literature

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sat, 20 Jul 2002 21:29:09 -0700 (PDT)


> >Knuth takes this literary approach with "The Stanford Graphbase", where
> >source code and commentary are joined together; it's quite nice.
>
> I read about this one or two days ago, when Guido posted some remarks
> about Leo on IDLE-Dev. But - it's a pity - I don't know nothing about
> it. I only feel, the idea sounds very interesting.
>
> Could you explain in short terms what this is: "The Stanford Graphbase".
> Is it a book? Is it software? Is it both? Or is it a website?  What is
> its content?

The Stanford Graphbase is a book, a collection of graph algorithm
programs, with commentaries embedded within each program.

    http://www-cs-faculty.stanford.edu/~knuth/sgb.html

What makes his programs distinctly different is that the order of
presentation in the book is decoupled from the way the program itself
constructed.

When we discuss a program, we might take a small chunk and start
describing it in detail, and take another small chunk.  We may not even be
writing a whole function, but may concentrate on a particular technique,
like applying a for loop.  It's sorta what we often do on Tutor.  *grin*


That is, we write program fragments primarily for human understanding,
because it's easy for humans to understand things in little pieces --- we
often try to chunk our programs by writing functions.

What his book does is show whole programs as a bunch of chunks, complete
with documentation.  Not only does he decompose things into functions, but
he goes one step further: he actually writes them as descriptive chunks.
All of the programs are written in this way, even the custom "flipping"
random number generator.  There's a separate program that weaves the
program back into the correct order.


> In what way can an ordinary Python user/trainer/teacher use it and what
> profit can she get from using it?

It might be hard to apply directly to Python, as the code is written in C.
But there are ideas about the way he presents the code that appeals to me.

I apologize for going so off topic from Python; I'm just something of a
Knuth fanatic.  *grin*  Sorry about that.



Another book that takes this idea of source code as literature is the
"Lions' Commentary on Unix 6th Edition":

    http://www.salon.com/tech/feature/1999/11/30/lions

This is another example of someone taking a fairly large program, and
distilling ideas and techniques from it.  The commentary occupies part two
of this two-part book, so there's a bit of flipping back and forth
involved, but it's still very nice.  And again, it's in C (and in a really
old K&R C, no less!), so it's not immediately applicable.

Darn it, we need something like this for Python.  *grin*


> P.S. Perhaps can rewriting (according to Alan's suggestions) and
> revising my snake-program make a story out of it ;-)

Yes, that sounds awesome!


Best of wishes to you!