Should code be readable?

Peter Seibel wrote a piece this past weekend on code reading – or rather, challenging it:

Code is not literature

I have to disagree. Or rather, I feel like he’s describing our current (defective) world, and taking it as a given that it’s how things should be.

Most code is unreadable. That is not a good thing, because it blunts or prevents one of the two major ways that you get better at something.

One way to get better is to just do it. And in fact, you will never get better at something unless you do it – you can theorize or otherwise gather information all you want, but that won’t help you when it comes to performing. However, there’s a limit to learn-through-doing, and that is that there’s just you, and you can only try so many things.

The other way to get better is to learn from others. Sometimes, but rarely, you can learn from them in person. But this doesn’t scale, so most learning is done through studying the output of others. You examine architecture, you deconstruct art, you read books.

It’s actually a shame that you need to decode programs in order to learn from them. While there is something to be said about the effort you put into learning something, it should not be herculean unless the payback you get is equally large.

In the past few years, I find myself rewriting programs to make them easier to read. I do this for myself, because I’ve found that I quickly forget exactly what I was doing, and if I have a hope of picking something up months or years later, I need to be able to read it. Fortunately, the same effort to make it more readable also makes it easier to work on, so it’s not lost effort.

And one thing really struck me, and that was the complaint that “in order to understand code, I have to rewrite it.” That is not a complaint, that’s a description of every other learning activity I’ve seen. If you want to really understand how a writer writes, you try to write in their style. For an artist with phenomenal skill or technique, you paint like them so you can learn it.

You don’t really understand something until you can make it.

Reading is an important step to understanding.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>