2009
09.22

One thing that often frustrates me to no end is to see the declaration of a variable whose name is meaningless. More often than not, this is caused by laziness. For example, if a variable could be named “delegate” but is instead named “delg,” my blood pressure is likely to rise.

What the hell is delg? anm? lm? I’m trying to read through your code, I shouldn’t have to stop and look for clues as to what you might be doing! In a loosely typed language, this is particularly painful, as there’s not even such a clue from the object’s type to indicate what something is.

Now, I should take a step back. I say lazy like it’s a bad thing. As a programmer, laziness can be a valuable asset. Laziness entices you to find the most efficient way to accomplish a task. Laziness may also entice you take shortcuts; but an experienced programmer should have the discipline and foresight to know whether or not a shortcut is appropriate.

To illustrate my point, a programmer might think to himself, “I really don’t want to type out delegate. That’s a lot of typing.” The good programmer would then ask himself, “How can I avoid typing that much without making my code worthless?” The bad programmer would jump to the conclusion that abbreviating the word would save him time.

Fortunately, for either programmer, there are elegant solutions. Namely, word completion.

Have you ever known someone well enough that you frequently knew what it was that they were saying long before they finished speaking? This is precisely what a good text editor should do. A well made text editor should be able to examine what it is you’re typing and infer what word(s) you might intend to type.

There are many such text editors, but my favorite is vim. In vim, if you begin typing a word, you can (by default) hit ctl + p to bring up a list of words which match what you’ve typed. Typically these might be found in the current file, but might be found in other locations in your source tree, dictionary, and so on. So If I wanted to include “delegate” as a variable name, but didn’t want to type the whole thing out, I can type “del” and let my editor complete it for me.

When I see “delg,” I can only assume one of two things. (1) The programmer who typed that was being robbed by his poor choice of text editors, or (2) the programmer was robbing himself by not knowing his text editor well.

1 comment so far

Add Your Comment
  1. Or maybe we want the code to have smaller size so that we can read it more easily :) I know – you already said this isn’t true – but think about it.

Search engine optimization by SEO Design Solutions