I wanted to keep my stories anonymous, but there is a very specific developer I want to write many stories about. I want to attribute those stories to the same person to build up his character, so I’ll always blog about him under the name Derek. Any other story, I’ll blog under the name Colin, and collectively, maybe Colin’s persona will match the insanity of Derek.
So here is a Colin story.
Just a background for those not familiar with C# or programming languages. If you want to store a number, you will often use the type “int” which is short for Integer; a whole number.
Colin had to program a countdown timer which took the time from a config file. Here was the Property he chose:
public int TimeInInts
The second word is the return type, so as we begin to read this, we know the Property returns an integer. What does this integer represent? A time. Fair enough, but in what unit? Ints.
Ints!
Absolute useless! Is it hours, minutes, seconds, milliseconds, something else? We don’t know without reading more code. That’s the telling sign of a badly named Variable/Property/Method; if you have to dig deeper to work out how you can use it.
I assumed it was minutes, but I look in the same file and there is another method.
public int GetTimeInMinutes()
{
return TimeInInts * 60 * 1000;
}
So GetTimeInMinutes uses TimeInInts in order to calculate minutes, so TimeInInts isn’t minutes.
Hang on, “* 60 * 1000“. That’s the calculation to convert minutes to milliseconds. So TimeInInts IS time in minutes and GetTimeInMinutes returns the time in milliseconds!
What.
The.
Hell.
How can you even write that, use it, and possibly get the feature working when everything you are dealing with has the wrong name?
Unbelievable.
Anyway, if you wondered where my username came from; now you know.
Lessons Learned
Always try to come up with the best variable names possible. Anything ambiguous, misleading or wrong will lead to confusion and bugs.