Saturday, March 10th, 2007

Use the Force, Read the Source

Have you ever had half a million lines of unreadable Java dumped on your desk with a request for “just a few small changes”? How did you feel when you realized there was hardly a comment to be found?

In such moments the eternal questions of the meaning of life rush to your mind. One of them is “What is the real purpose of source code?” Think a second before you continue.

Source code is there to be read by people. That’s right, to be read by people. Lots of developers write their code “for the silicon”, for the CPU. But silicon couldn’t care less about Java or C#, classes, methods, and design patterns. Such things are there only to help people think. The source code is compiled into bit brew before it reaches the silicon. All signs of classes and design patterns are completely gone. The CPU has no need of source code.

Source code is person to person communication. It is written once, but read tens, perhaps hundreds of times by human readers. The first reader is the original programmer. This may sound as if programming is like writing a book. One of the famous pioneers of computer science, Donald Knuth, took this to the extreme. He introduced literate programming and published some of his well-known programs as books for people to read.

You don’t have to go that far. But consider the factors that make your code survive for one year in your shop. One of the main points is how well it communicates what it does. Requirements are for ever changing. This translates into constantly changing source code. If what you did is too hard to understand, chances are someone gives up, ditches your precious gem and writes a replacement.

And then correctness. Correctness cannot be tested, only designed. Testing can only prove the absence of correctness. You cannot determine the correctness of something that cannot be communicated. Code inspection is a kind of formal communication. It can be very efficient, but is seldom used. One reason is that many people write their code for the silicon.

Next time you code, remember you are an author! You don’t have to use a quill pen and ink. You don’t have to aim for the Nobel prize. But you do have a message, not primarily for the CPU, but for your colleagues.

Comments are closed.