Cadence of Code
What's to learn from retyping code?
I was on vacation and paused the newsletter for two weeks. Now I’m back. Thanks for reading.
Hunter S. Thompson, author and journalist, typed out other people’s writing – entire novels, even – to learn from them. In his words:
If you type out somebody’s work, you learn a lot about it. Amazingly it’s like music. And from typing out parts of Faulkner, Hemingway, Fitzgerald - these were writers that were very big in my life and the lives of the people around me - so yea I wanted to learn from the best I guess."
To learn what exactly? Here’s another quote:
He used to type out pages from “The Great Gatsby,” just to get the feeling, he said, of what it was like to write that way
Just to get the feeling.
I’ve read a lot of things by and about Hunter S. Thompson in my teenage years and can’t recall where I first came across this practice of his, but I do know that I’ve been thinking about it for over a decade.
What I remember is Hunter saying that he did it to get a feel for the rhythm of someone’s writing. Maybe I misremember him using the word rhythm, but based on the quotes above, it probably wouldn’t be something he disagreed with.
I’ve always wanted to try it, typing out a novel. There’s something to the idea of letting a piece of writing flow through you, one keystroke at a time.
Typing out a lot of other people’s code – that I did. Whenever I follow a book that contains code and it’s a book I truly want to learn from, I type out the code while following along. No copy & pasting. I’ve done it this way ever since I started programming and learning from books. Not sure exactly why, maybe because copy & pasting always had a smell to it? Maybe it felt like skipping the actual work when you don’t type it out?
When I read Zed Shaw’s Learn C The Hard Way years and years ago, I got confirmation that I’m not alone with this. In the introduction Zed sets some rules for following along:
Type in all of the code. Don’t copy-paste!
Type the code in exactly as it appears, even the comments.
Get it to run and make sure it prints the same output.
Even the comments.
It sounds like a dumb, mechanical exercise, doesn’t it? An exercise for exercise’s sake. Typing out comments – what good can that possibly do?
I’m not sure, but I agree with him. In the introduction of Writing An Interpreter In Go I don’t set rules, but nudge:
This book is meant to be read from start to finish and I recommend that you follow along by reading, typing out and modifying the presented code.
I’m no educator and don’t have a single degree, so I’m absolutely out of my depth here, but I do think you absorb more if you actively engage with something instead of merely reading or listening. Typing out a bit of code, at least to me, seems to have a better learning effect than only reading it.
That makes me wonder: if Hunter S. Thompson typed out Fitzgerald & Hemingway to become a better writer, which code should one type out to become a better programmer?
typing.io, which I’ve used a long time ago to practice my touch typing, has a nice selection: Redis’
sched.c file of Linux 0.01,
Collections2.java of the Guava, parts of jQuery, Ruby on Rails, some Perl, and a lot more in other languages. Yet the main goal here is to get better at typing, not to get better at writing the code.
What would be on a list compiled specifically for that latter purpose? Pieces of code to type out, character by character, “just to get the feeling” of it, to maybe get a glimpse of the thoughts that made the fingers move when the code was originally was written?
Gary Bernhardt once said that he enjoys the “cadence of typing”. Or maybe he didn’t, because I can’t find a source, but I’m pretty sure it popped up in a variation of the talk “Learning from the masters” that Geoffrey Grosenbach gave at Railsberry in 2012. The only thing I can find, though, is a recording of that talk from 2013, at RubyConf AU. That doesn’t have the quote I’m referring to, but it has this wonderful section in which Gary explains how prefers one way over another to delete 2 lines in Vim because it saves him 1 or 2 keystrokes.
Maybe it’s not possible to recreate thought through retyping. Not sure. What I do know – on a non-scientific, talking-out-of-my-ass level – is that certain pieces of code have a certain rhythm, and if nothing else, getting a feeling for that rhythm – the cadence of the code – by retyping, well, it doesn’t sound like wasted effort to me.
Thanks for reading. Subscribe here: