Print Out Your Code. On Paper.

Neven Krcmarek x Carl Tashian collaboration
Neven Krcmarek x Carl Tashian collaboration

Reading code is hard work—in some ways harder than writing it—so most of us have a tendency to avoid looking closely. There is a practice I learned about long ago called desk checking that seems to have gone out of favor in a world of incredibly sophisticated IDEs, but I believe it still has a lot of value.

To desk check your code:

  1. Print it out
  2. Find a quiet room
  3. Bring a pencil
  4. Leave all devices behind. Take off your smart watch. Fold up your laptop. Leave your phone at your desk. This is between you and the code.
  5. Sit there and read your code line by line. Mark it up as you go.

You’ll learn something every time you do this.

Here are some questions you can ask:

You’ll also find bugs, naturally. When you slow down and look, bugs will just start crawling right off the page. Sometimes they will take your breath away, and you’ll leave wondering how the damn thing ever ran in the first place.

How to print out code, with syntax highlighting:

There’s an ancient but useful command line utility for this, called enscript.

On MacOS with Homebrew, you’ll need to brew install enscript first.

On Linux, you may already have it. If not, look for the package enscript or download it here.

To print your code, run:

enscript -1rG --line-numbers -p --highlight=python \

The output file will look something like this:

Then you can either open (on MacOS to open in your default PostScript viewer), or print it to your default printer with lpr

Enscript has a lot of options. Here are the most valuable options:

-1 -2 -3 -4 number of columns per page -r rotate (landscape mode) -G fancy header (with filename, date & time) --color=1 if you have a color printer -w htmlj if you want HTML output instead of PostScript --help-highlight will show which languages have syntax highlighting available

Here’s a nice looking version that adds --color=1 and -2. If your line lengths aren’t out of control, this is a good starting point.

enscript -2rG --line-numbers -p --highlight=python \
  --color=1 -c

Code can be quite beautiful at rest—if you take the time to really appreciate it. You have the tools, now set aside the time.

Printing code on MacOS
Linux Printing Guide