Tuesday, November 24, 2009

Misspelled variable names

As a computer programmer, I face a conundrum whenever I see a variable name that is misspelled. For those of you who aren't programmers, variable names are words that exist in the source code (written in C or C++ or Java or whatever) of a program. Source code gets compiled into a binary executable, which is the thing you actually run.

For anything that's actually seen by users---prompts, error messages, configuration files---I, of course, insist on proper spelling and grammar. That's just part of putting out a quality product. But variable names aren't seen by anyone other than fellow programmers, and when a variable is used many times throughout a program consisting of thousands or millions of lines of code in perhaps hundreds of files, changing it is time-consuming and risky. The benefit is questionable, too; it might be easier for future programmers using that variable to remember it, but compilers will catch inconsistencies in spelling anyway.

My general practice is to leave the misspelling but grumble about it as often as possible to anyone who will listen. The latest one I encountered today was DELIMITER (something like a comma or space or tab to separate fields) misspelled as DELIMETER. People really don't think before they spell. The word "delimiter" comes from "limit", which this programmer presumably knows how to spell. "Delimeter" looks like "Deli-meter" to me, which looks like something a sandwich shop might use to keep track of sales or ingredients.

3 comments:

Richard C Haven said...

Coming from Delphi (Object Pascal), I find case-sensitivity of the rest of the world's languages annoying: human beings are not very case-sensitive.

I find misspellings as deserving of correction as etymological failures. Most IDE's help with refactoring, and a good variable name helps with code's effectiveness and durability.

Ideally, a variable should not need a explanatory comment because its name explains its use.

Cheers

Language Lover said...

Thank you for your comment, Richard! I like the case sensitivity of C/C++/Java, if only because it allows for easy reading of multi-word variable names without using underscores everywhere.

What do you mean by "etymological failures"? I hear what you're saying about IDEs making variable replacement easy (and I would also add that they detect case sensitivity errors quickly ;) ). The cases I'm talking about are not usually ones where the typo prevents understanding of the variable name. I know what my fellow programmer meant by "DELIMETER"; it's just annoying to see.

Richard C Haven said...

Case sensitivity means that totalDifferenceofAmounts is not the same as totalDifferencesOfAmounts, and (unfortunately) it is not unknown to dynamically create a property with meaning to in today's squishy (loosely-typed) languages.

Pascal tends to use CorrectCase (rather than camelCase) instead of underscores.

Misspelling a name, especially in abbreviation, can actually create a different meaning: totRpt vs. totRqt.

Although it might be annoying to see the word DELIMITER spelled out, the cost to the project of one reader misunderstanding a word (or taking a few times extra to understand it) is far greater than your occasional annoyance with the lack of written jargon.

Cheers