On Programming Well

Programs must be written for people to read, and only incidentally for machines to execute.

Structure and Interpretation of Computer Programs

Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better.

– Edsger Wybe Dijkstra

I’ve been programming for 9 years and it’s only beginning to dawn on me how important these quote are. Like bacteria, programs want to keep growing and growing, both in size and complexity.

It doesn’t help that engineers (like myself) keep feeding the beast. Complex programs, ones that only we can understand, gratify the ego. And well, the job security helps too.

But I’m tired of shitty software. I’m tired of using it, working with it, writing it, re-writing it… I just want to rest.

Good programs are like good writing. I’ll quote William Strunk:

A sentence should contain no unnecessary words, a paragraph no unnecessary sentences, for the same reason that a drawing should have no unnecessary lines and a machine no unnecessary parts.

Likewise, a good program should contain no unnecessary lines, no unnecessary bytes. Give me the code that works, is correct, and is fast – no more!

I wish I knew the secret to keeping software just the “right size”. Like good writing, it seems like the only consistent path is to keep re-writing and re-writing. Every draft you cut a little more fat off the project. More and more, until all you’re left with is skin and bones.

Learning how to program well is a lot like learning how to write well. I didn’t learn how to write through grammar exercises. I learned by writing and reading. A lot. It was the practice that made me improve.

I spent far too much time reading about different tools and design theories and architectures. Some of it helped, but most of it wasted my time.

If you want to get good at writing simple programs, you need to program a lot. You need to read a lot of programs too. Nothing else will develop your eyes, ears, and fingers more than the millions of lines of monospace you’ll read and type. If you are more talented or clever than me, you’ll do it in fewer lines. Probably an order of magnitude fewer lines (I’m not particularly smart).

I wish I had some secret to share with you. I wish I could say more than, “good programming is a matter of taste, and you just have to pick it up.” But that’s all I got.

Good luck. You’ll need it.