Avoid Single Letter Variable Names

One of our sites gets an occasional error that position 12 of array "b" cannot be found. When I look at the code for the page, it has no comments as to what "b" is or where it was created (not in that file, needless to say).

Now, if the variable name had been descriptive ("aBacks", for example) then I would have some clue what it did without comments. I would also be able to search for it. I could search for "b", but that wouldn't really be helpful. So, now I have to go through a tedious process to find the problem just because the programmer used a single letter variable name.

I recommend that you avoid single letter variable names in all cases. Although this example wasn't my code, I will confess that I have used single letter variable names for loop iteraters before ("i", for example). No more! Even if I can't think of a goto variable name, I will at least use "ii" so that someone might be able to search for it.

In this case, the site architecture was pretty simple, so the problem didn't take long to track down. Even so, it would have been much easier with a real variable name. 

So the next time that you are tempted to use a single letter variable name, please resist.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
WOW... good point I really hadn't thought of that!
# Posted By Ryan Everhart | 2/27/07 2:35 PM
I don't advocate one letter variables at all... just an alternative solution: any decent editor should know about regexp searches. Open your file in vim and type `/\` (without the backticks). Or even better, place your cursor below the variable and press * to search forward in the file or # to search backwards... You probably guessed by now that I advocate vim ; )
# Posted By eels | 2/27/07 6:44 PM
Eels,

Good point. I rarely think about using regexp for searching code, but it really is a good option to remember.
# Posted By | 2/28/07 2:19 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.