Skip to main content

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.

No Comment

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.

Read Article...

Constants

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.

Read Article...

nomen est omen

The Romans used to say

“nomen est omen”
By this they meant that a person's behaviour or characteristics were influenced by the person's name.

Shakespeare, however, had Juliet say to Romeo:

“What's in a name? that which we call a rose
By any other name would smell as sweet”
This, of course, has the opposite meaning — no matter what you call a rose, it will still be a rose.

So who is right, and what does it have to do with programming?
Read Article...

The Unknown

Donald Rumsfeld famously said:

“... as we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns — the ones we don't know we don't know.”

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...

Spaced Out

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.
Read Article...

Copy Right

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.
Read Article...