Reading Programs
March 11, 2021 in development, thoughts

Programming is similar to writing in so many ways. One way to learn writing is to write, but one also learns to write by reading. We read examples—both good and bad—to facilitate learning. But how many programmers learn to write programs by reading programs?

In his book On Writing, Stephen King proclaims:

If you want to be a writer, you must do two things above all others: read a lot and write a lot. There’s no way around these two things that I’m aware of, no shortcut.

I believe the above passage applies equally well to the craft of programming. To paraphrase Mr. King,

If you want to be a programmer, you must do two things above all others: read a lot of programs and write a lot of programs. There’s no way around these two things that I’m aware of, no shortcut.

Each program that you read teaches you something. Bad programs teach you what not to do. Good programs teach you how to write clear, readable, maintainable code.

Great programs can also inspire you, motivating you to work harder and aim higher. Being humbled by reading great programs. You cannot hope to inspire someone and sweep them away by your programming skills until it has been done to you.

Here’s what Gerald Weinberg has to say about the process of reading programs. From his classic The Psychology of Computer Programming,

The most important reason for studying the process by which programs are written by people is not to make the programs more efficient, more compact, cheaper, or more easily understood. Instead, the most important gain is the prospect of getting from our programs what we really want—rather than just whatever we can manage to produce in our fumbling, bumbling way.

Read bad programs to recognize those bad practices when they begin to creep into your own work and to steer clear of them. Read good programs to measure yourself against the good and the great, to get a sense of all that can be done.

Reading programs offers you invaluable knowledge of what has been done and what hasn’t, what is stale and what is fresh, what works and what doesn’t.

When was the last time you read a program?

If you are a programmer, when was the last time you read somebody else’s program? When was the last time somebody else read one of your programs and discussed it with you?

If you are a first-line manager, are you capable of reading the programs written by your programmers? Do you read them?

If you are a higher-level manager, are your first-line managers capable of reading programs written by their programmers? Are you sure?

Let’s wrap up with another quote from Stephen King.

If you don’t have time to read, you don’t have the time (or the tools) to write.

Simple as that.

Stephen King
Stephen King