Long lived code
Anyone who has spent some time maintaining, updating, porting and enhancing programs that were coded by someone else appreciates the challenges of trying to decypher and understand another's code. Sometimes even the original author of the code will face the same challenges if it has been some since the code was written.
Often it is incomprehensible. Even if it is comprehensible, it might still takes considerable effort to understand what the code is doing and how it goes about doing this.
By using a modicum of discipline in adhering to some simple principles, programmers can write code that is easily comprehensible to anyone who has to pick up the pieces.
The articles in this blog illustrate some of these principles.
Comments in code are wonderful. They can clarify a bit of code that is otherwise quite obfuscated, allowing the reader to figure out what is happening. They can be used to generate pop-up help in code editors to give programmers help how to use a function or method. They can be used to indicate the history of a method or function and maybe some pitfalls to watch out for.
Consequently project managers and company policies often dictate that every function, method, parameter, property or class be commented by the programmers.
But this is not always a good thing. Coding is much more fun than writing comments about it; So the comments are often given much less attention than they deserve.
We regularly use constants in calls to method or functions or to keep track of an objects state. Since computers are best at dealing with numbers these constants usually are integer values.
But the problems for us humans is that we cannot keep track of what each of these values represents.
nomen est omen
The Romans used to say
Shakespeare, however, had Juliet say to Romeo:
By any other name would smell as sweet”
So who is right, and what does it have to do with programming?
Donald Rumsfeld famously said:
At first is seems whimsical and likely to incur great mirth, but a closer look reveals that it has a lot it has a lot relevance to long lived code.Read Article...
White space is one element of code that is ignored by the compilers or interpreters of most computer languages. It has no programatic value at all. Yet it has an enormous impact on comprehension.
It is how we use it that ultimately governs how readable the code becomes. Proper indenting and use of blank lines can provide an immediate sense of the structure of any code.
This has nothing to do with intellectual property. Instead it is really about using Copy and Paste intelligently.
Computers are really good at repeating things over and over again, whereas humans are not. So when it comes to repeating similar tasks, we should instruct the computer to repeat the task instead of us repeatedly instructing the computer to do the task.