Scientific Programming “Don’ts” – Badly Named Variables

I once knew a software engineer who gave birth to identical triplets.  Since no one could tell the babies apart, she named them all X and planned to assign a string to each one later. For various reasons, she never did.  Since she and her husband never did learn to tell them apart, they continued to dress them identically, feed them the same foods, and enroll them all in the same pottery class, where they made three identical misshapen clay vases. Years later, the oldest triplet gave birth to twins whom she named X1. No one could tell them apart either. Except for one thing. The older twin always gave meaningful names to her variables and she went on the great success. What can I say, they were an odd family.

Variables used in software code, unlike newborn babies, are not interchangeable.  To keep your code orderly, and usable for future colleagues, it’s important to choose meaningful names for your variables. For example, if you implement a calculation that was presented in a published paper , try to use names as close to those you’ve used in the paper as possible. This will help people follow your code.

Here at the Research Software Company, we once inherited an old program that we needed to update. They had implemented a calculation that was published in a paper. The code had a matrix named M, a vector named g and a result vector that was named s for the duration of the calculation. In the code g was indeed called g. The matrix M, however, was called ‘vec’, and the vector s was called ‘tmp’ in the code.

Which brings us to another thing you shouldn’t do – don’t call your matrix ‘vec’. And definitely don’t call your matrix Neo. Too nerdy and cliche.

Leave a Comment