I’d like to buy a vowel…

Back in the day, variable names were limited.  You might only have 8 characters to describe whatever piece of data it is you are working with.  Thankfully, that’s no longer the case, and it hasn’t been for some time.  You shouldn’t ever be afraid of using variable names or function names that explicitly state what you are doing.  Naming your function “fun()” isn’t going to help anyone.  Naming it “computeCentroid()” will.  I really don’t see a lot of benefit in shortening single words, like using “desc” instead of “description”, unless variable and function names are already getting long.  In such a case, pick one, and be consistent with it.

At the same time, don’t be too wordy.  When first starting into a project, which involved converting an old Microsoft Access and Visual Basic project into a Django based web service, we were dealing with a name like “Sub-terrain Frobnicating Zone”.  Because we weren’t familiar with its abbreviation (STFZ), we were naming variables like “localSubTerrainFrobnicatingZone” or “heliocentricSubterrainFrobnicatingZone”.  This got pretty old, pretty quick.  After working with the project for a little bit, we quickly adapted the abbreviation of STFZ.  So the above variable names would become localSTFZ or heliocentricSTFZ.  Much more manageable, but still descriptive, assuming you knew what an STFZ was (which was covered in the project readme).

The beauty of working with good tools and statically typed languages is that your tools can tell you what type something is if you mouse over it.  For example, if the above code was C#, and I was working in Visual Studio, I would only need to mouse over a variable name to see what type it was.  So there’s something to be said about naming a function “ComputeCentroid()”, and being able to see what it takes for parameters and what it returns, rather than naming it “ComputeSubterrainFrobnicatingZoneCentroid()”.

tl;dr – Be concise and consistent in variable and function names.

Advertisements

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 )

Google+ photo

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

Connecting to %s