A variable’s name should correlate to the size of its scope.

The larger the scope, the harder it is to fully understand.

In a tight loop with a scope of one line, a variable’s name can be one letter. This is often an array index or some kind of counter.

As the scope gets larger, the variable name should become a word representing a business object.

When the scope of a variable exceed that of a single method, there definitely becomes a stronger chance of confusion, so the name may need to involve multiple words.

In all cases the variable’s name should be immediately obvious to the reader. And when they see a really long name, that should be a red flag to the reader that this variable may have an extended scope.

Leave a comment