Original question from Quora:

What is the worst name for a variable?

In another question someone noted debugging “smallIllustration”.

My Answer:

The worst name for a variable is something that is short and doesn’t make sense.

Programming is not math. It’s programming. A lot of programmers like to use short, single letter variable names and it makes reading code impossible.

Imagine if before writing the next paragraph I decided to substitute the word variable for the letter v.

This is a horrible way to name a v because every time you use the v you have to substitute v for v to understand that we are talking about a v named v and not the letter v. That is why whenever you name a v you should use a proper name for the v instead of using a single letter v, an acronym for v, or even shortening the word v to make the v fewer letters to type.

Now, while that is horrible to read, especially if I were to declare the word variable is now v 500 lines above in some at the top of the method or source file or something.

[sarcasm] Luckily for me, it was easy to type and as a programmer with no empathy for myself or anyone around me, I saved a few keystrokes.[/sarcasm]

So, when naming a variable, remember that code is meant to be read and that you should optimize for reading the code, not writing the code. If you don’t like using descriptive names, get an IDE with code completion.


P.S. Have you subscribed to Code Career Genius yet?