- Software Engineering Forum
Well Named Variables -- For Whom?

  Posted by henyge, 11 Apr, 2016
 412
             
My question, though, is how do you decide which people you are addressing?

I'm starting this thread because something struck a chord in me when somebody commented on somebody else's code that they should use well name variables. The code used a lot of one or two letter variable names. On closer look, though, the code was very deeply steeped in what looked to be modeling a physical phenomenon. I'm willing to bet that to somebody who is familiar with the equations involved in the simulation, the variables would have made perfect sense. For folks like us who are just trying to understand why it crashed, but don't know jack about the subject matter, the variables would have been meaningless.

So the question then is do you write the code for people who will dealing with the code day in and day out, or do you write it for the Joe Random Consultant who you pull in?

Or here's another example: For a statistical program which variable name do you choose: stardardDeviation, stddev, sigma, s, or σ ? (The latter is probably only a choice if your compiler supports it.)

One could say, that is too esoteric. For normal applications, people wouldn't use single letter variable names. If that's true, then why do we have:

struct Color
{
int A, R, G, B;
}

and

struct Point3D
{
int X, Y, Z;
}

Shouldn't they be:

struct Color
{
int Alpha;
int Red;
int Green;
int Blue;
}

and

struct Point3D
{
int XCoordinate;
int YCoordinate;
int ZCoordinate;
}


Or is dealing with colors and 3D points still too specialized a field, and it's assumed that you are "a person skilled in the art"?

As a tangent, compare the pseudo-code on Wikipedia for Dijkstra's algorithm and A* algorithm. The former seems to be written for graph theory enthusiast, while the latter seems to be written for high school student who just needs help with their robotics project. Now imagine reading the A* algorithm pseudo-code in the same terse identifier names.

In most places I've worked at, the general philosophy was to dumb down the code so that you could hand it off to an entry level developer. I've questioned it in the past by going: "If that is the intent, then why do we tell HR that we need people who have past experience in this specialized field?"

Replies to: Well Named Variables -- For Whom?

henyge

Re: Well Named Variables -- For Whom?

My question, though, is how do you decide which people you are addressing?

Educational Partners

Copyright © 2016, Aptech Computer Education - Ghana, All Rights Reserved.