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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: