Variable names should describe what, not how.

Leave the how to the implementation.

Naming variables well is very important to creating code that can be easily maintained in the future. One key important thing to remember is that the name of the variable should reflect what the variable represents, in a business sense.

Some people make the mistake of using words that describe the technical implementation of the object instead. This often leads to vague names where the future reader is not sure what business object the variable is referring to.

Watch out for variable names that use computer terms instead of business words from the domain. For example, inputRecord, bitFlag, and calculatedValue. Yes, this is a record from the input stream, but what kind of record? A shipping record? A customer record? Wouldn’t have been clearer to say customerRecord instead?

And yes, a bit flag uses a bit and can be one or zero. Typically this indicates either a true/false or on/off condition. But this name doesn’t tell us either and gives us no clue what business thing is supposed to be true or false.

Similarly, a calculated value. We are writing programs here; they’re full of calculated values. What are we calculating? It’s a big mystery.

Take the mystery out of your code. Future you will appreciate it.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: