Exploration Through ExampleExample-driven development, Agile testing, context-driven testing, Agile programming, Ruby, and other things of interest to Brian Marick
|
Sun, 25 Jan 2004My first event in the Master of Fine Arts in Software trial run was a lecture on code-reading in the style of the literary critic Stanley Fish. His "affective stylistics" has one read a poem (say) word-by-word, asking what each word does for the reader. What expectations does it set up? or overturn? What if that word were omitted or moved elsewhere? (I've written on a similar topic earlier, and I drew my examples from that entry.) I compared idiomatic Lisp code, "C-like" Lisp code, idiomatic C code, and Lisp-like C code to show how expectations and membership in "interpretive communities" influence readability. In the process, I learned something unexpected. I presented code like this to Dick Gabriel, expecting he would think it an idiomatic recursive implementation of factorial. (defun fact(n &optional (so-far 1)) (if (<= n 1) so-far (fact (- n 1) (* n so-far)))
He didn't think it was idiomatic, not really. He found it somewhat old-fashioned,
preferring an implementation that replaces the optional argument
with an internal helper function (introduced by
the (defun fact (n) (labels ((f (n acc) (if (<= n 1) acc (f (- n 1) (* n acc))))) (f n 1)))
Now, I always hated
The It's arguable that my reading style is just flat-out worse, but I do think that tuning reading to writing is a more useful way to think about it. All this may seem small, but it reinforces my idea that attending closely to the act of reading will yield some Aha! moments to improve our practice. |
|