What's in a Name?

A project I've been involved with for two years involving major refactorings to our over 4,000 classes project has led me to some dark corners in the sources. Working with code that is unknown to me has made one issue very pressing—names. I'm not talking about syntactical issues, which are covered in almost every coding standard and generally agreed upon. Rather, I'm talking about the relation of a name and the meaning or semantics of the concept it names.

In this project I often encounter names that lead me on the wrong track, and, after spending valuable time on something, I finally feel that somebody has played a good joke on me. In the end, most of the designing, modeling, and code writing capture some concepts that are grounded in real-world counterparts. For these concepts you need good names to easily establish the relationship from virtual to real. Other concepts are pure inventions without a real-life counterpart. These, even more so, need good names to visualize their meanings.

Is it hard to choose good names? I don't think so. Most programmers take a casual approach to this task. After all, laziness has been cited as one of a programmer's biggest virtues. Being focused on getting the work done means that naming is perceived as an obstacle that gets in the way. Code will run just as well if you name a variable "a" or if you name it "averageGasConsumption." Still, a name is meant to communicate something to those who will work with the code after you have finished it, and that may even be you a week later. You'll write that line of code only once, but chances are you and your team will be reading it a dozen times later on. Several factors contribute to poor naming habits.

Poor instruction If your instructors spent more time on lessons of good naming than the occasional lecture to "choose expressive names," you are lucky (and went to a different university than I did). For sure, if you named those variables in your calculator homework assignment "a" and "b," you'd get back some bad remarks, but "result" and "plus" would have been dandy.

View Entire Paper | Previous Page | White Papers Search

If you found this page useful, bookmark and share it on: