Good climber

I once heard a word from an adept climber. When they climb a mountain, they have to watch their step. However there are many steps on the way, and they cannot pay full attention to each step. Good climber knows where he has to pay special attention, where he might fall if he made a mistake.

I remember this word when I do programming. We cannot pay full attention to all the statements in our program. We use some help to ease our brain while we are programming; such as,

– Rely on visual aid on the editor.
– Rely on compiler warnings.
– Patrol in a program by using regexp search.

Good programmer knows where bugs may slip through those protections, and pays special attention to write such statements.

Massive copy and modify is one such case. For example, suppose you copy a line like this to make more entries.

    { "", funcA, helpA, dataA },

Some missing commas are OK because compiler will find them.

not too bad:

    { "alpha", funcA, helpA, dataA },
    { "beta" funcB, helpB, dataB },
    { "gamma", funcC helpC, dataC },

But if you forget to modify some part of the data, probably the program still works in a wrong way, which may be hard to find.


    { "alpha", funcA, helpA, dataA },
    { "beta", funcB, helpB, dataB },
    { "alpha", funcA, helpC, dataC },

This is when good climber’s intuition comes in. It is dangerous because nobody protects your mistake. You need to switch to careful mode. For example, I would search through the file with regular expression “A\>” to highlight all the As at the end of the words. Nowadays, nice text editor highlights all the occurrences, then I see all the corresponding “B” and “C” are there.

To make this sort of check work, you have to use consistent name. And note that I would miss the fact “gamma” is not there. If I had had used more consistent name like funcAlpha, then I could have searched by using regular expresson “alpha”, then I could have easily found that “gamma” was not there.

Rules of the thumb: You don’t have to be too careful when you are typing the following stuff.

– names
– punctuations

But you have to be careful when you type

– numbers
– strings
– operators

Whenever you do massive change such as duplicating lines of codes or changing names in a file, use regexp to systematically replace and check what you did.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s