Write code to be read
Juten Tach,
i am currently reading “Code Complete” from Steven McConnell. I encourage you to read it, too. He’s a good writer and the book contains a lot of usefull tips and insights into software design and programming. Today one particular little paragraph caught my eye. It has the headline “Favor read-time convenience to write-time convenience“. I couldn’t agree more.
He continues with “Code is read far more times than it’s written, even during initial development. Favoring a technique that speeds write-time convenience at the expense of read time convenience is a false economy.”
[Update]: As i was turning to “Refactoring” from Martin Fowler lately i saw him making the same point: “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
Programmers (including me) can be very lazy and very often you say to yourself “I know this is dirty, but i want it off my back and it works, so who cares”. But you can be very sure, things come back sooner than you think. Writing code in a way, that simplifies writing it, ignores the fact, that very often you have to deal with that code for quite some time after the initial development. Perhaps not the original developer, but perhaps someone else, which makes things even worse.
This begins with naming functions and variables. Of course it is easy to give a variable a name of “o”. You will only have to type one character for using that variable, so it makes writing your code easier at first glance. But “o” says nothing and will make your code harder to understand.
Also i often see programmers hesitating of writing a class for specifying some abstract object, like some specific event, for example, because it feels to be annoying to write additional code. Especially in AS2, when you could simply make up an event object by simply writing : {type:”myEvent”, target:this, myparam:”hello”}. Of course, it was easier to do so instead of writing an event class. But it made understanding code for someone else a pain, because now there was an untyped object, which made it hard to guess, that the important parameter in the event was called “myparam”.
There are lots of examples, where aiming for easying of writing code results in less readable code and thus makes it less maintainable.
