K. Sabbak

Code Princess

Copying Code for Comprehension

May 25, 2018

I think I'm a kinetic learner. That's why I print out my code when I refactor. That's also why if I want to get anything out of printed code examples (excepting the smallest/shortest of examples), I have to type them up myself. I've been reading Agile Software Development: Principles, Patterns and Practices (PPP) lately, and Robert Martin really, really likes his code examples that span pages. Maybe there are people out there who can get something out of just reading those examples, but for me, it's way too much to keep in my head at once, especially without language highlighting, but also in general.

Starting in Martin's Clean Code, I started copying his code down onto post-its. While there were a lot of shorter code examples in that book, sometimes the code we needed to compare was on opposite sides of the same physical page, and after flipping back and forth for the dozenth time did absolutely nothing to help me understand the point he illustrated, I started writing it by hand so I could see it side-by-side. Then I started writing code out by hand as the book progressed so I would have a better understanding of what changed in each iteration he printed.

Code examples in a book with post-its covered in hand-written code over some of the text
My handwriting is unreasonably small.

But with PPP, code examples span entire chapters significantly more often, and I couldn't just skim the code in order to get “some idea” of what was going on, nor was there any way that was going to fit on a reasonable number of post-its. I started typing out his examples on my own in Sublime — I considered using IntelliJ, but the point wasn't to build the project, just see the code in one easy place. So I started retyping the code in one file, and then the refactor in a new file, and that refactor in its new file, etc. I ended up with seven files, corresponding to the book.

Sometimes, when typing “TimeSink” over and over again, I'd wonder if that's what I was doing, but in the end, there was no way I was going to follow seven iterations and understand all the changes if I hadn't typed it up on my own. I know this because I tried. I hadn't even noticed the typo on the bottom of page 311, which is SUPER obvious if you are paying attention.

I hadn't done this will all of the examples. Sometimes it was because I was reading on the train, but mostly I had bought into the idea that I should be able to read code well enough that just reading was going to cut it. Maybe I'm not there yet. Maybe I'll never be there, at least for printed code that also has a temporal aspect to it. The reality is, just because books are meant to be “read” doesn't mean that the best way for everyone to get all the information out of them is to just read.

I don't want to type everything up going forward, it takes a while. But I also don't want to stunt my learning because I'm lazy, so I'll be typing up the code examples from now on, I'll just probably also whine about it.

Tags: reading fundamentals old-school