Saturday, 31 August 2013

When can I get away with using short variable names?

When can I get away with using short variable names?

I often find that people stress using variable names that appropriately
and accurately describe what the variable is trying to convey. This is
also often very hard to do in a word or two. I find it true that though
longer names are typically more accepted, they often lead to code that is
even less readable because of mere clutter. I find that once I understand
what a variable conveys, the name is merely an alias for that
understanding, and that the name itself does not necessarily make a
difference. In that case, I would personally almost always prefer shorter
names to longer ones.
Is it ever appropriate to use short variable names? Is it acceptable to
use names that aren't necessarily understood without looking at the rest
of the algorithm or class, but perhaps which are commented at declaration
of the variable or beginning of the algorithm? Or is it generally always
preferable to have longer names that immediately and definitively convey
meaning?

No comments:

Post a Comment