Arduino Intro Labs for Tangible Computing
7. How to Read a Program
Thoughts based on How to Read a Book, by Mortimer J. Adler and Charles Van Doren. Touchstone Press, 1940, 1967, 1972.
Elementary Reading is about how to recognize the parts of a sentence (aka statement), and ask: "What does the statement say?"
Difference: program statements are nested structurally in a way that English prose (typically) isn't.
Inspectional Reading is the art of skimming systematically to get the most out of the program in a limited amount of time.
What is the program about?
What is the structure of the program?
What are its parts?
What kind of program is it?
Inspectional reading gives you the structural view which you then use to direct your more detailed exploration of the program. It is broad and shallow.
Difference: program structure is non-linear because of modularization. Narrative can also be non-linear, but I have yet to see a book modularized to the extent where a chapter begins: Please instantiate the "Evil step mother and nasty sisters plot." with the arguments: Mother <- Edna, NumSisters <- 3, Heroine <- Rapunzel. Action movies of course employ this kind of reuse all the time.
Analytical Reading is a more complex and systematic reading of the code for understanding. It is a narrow and deep exploration of the code, examining behaviour and data in detail. Analytical reading is driven by questions and hypotheses. "What does this fragment do? I think it sums the odd integers not divisible by 3."
Analytical reading is reasoning about the program: theory formation with confirmation and refutation.
The problem of state: Reading a program requires you to imagine it executing over time (even for pure functional programs). In this sense, it is like reading a musical score. You have to "execute it" to hear the music. But a program is not like a musical score! With a musical score you can leap into any point of the score, and the notes describe exactly the next state of the piece (ignoring repeats which are a form of modularization). With a program, you have to run the program in order to reach the current state (i.e. the one that applies to the line of code you are looking at). This is what makes understanding a program hard, and is why we invented the notions of pre-conditions, post-conditions, and invariants that describe what the state looks like at certain points. Oh yes, and comments help here too, just like they do when reading "Literature" (See A Skeleton Key to Finnegans Wake by Joseph Campbell and Henry Morton Robinson.)
Syntopical Reading is all about reading many programs, comparing them, and reaching overall conclusions about style, design, architecture, and so on. Expect at least ten thousand hours of computing experience before you get to this stage.