games and code code it, play it
Variable names
February 7th, 2009

For a few last weeks I was attending many developer meetings. We have been planning a new product and I’m trying to assemble a team who is capable to do it right. Trying to guide a diverse group of developers when they are exchanging their approaches to development can be amazing experience. There are many rules to agree on when going into collaborative construction. If we agree beforehand, there wont be many disagreements when actual coding begin. Most of the code will be written by one person but afterwards read by many and that’s why it’s important to be written clear. One of the issues we agreed on is naming the variables.

Names in code are important. Compiler will let you use almost any kind of name and it doesn’t really care. But if programmers are not careful with choosing names for their variables, reading the code is much, much harder. “I’m typing this on a keyboard, sitting on a chair while listening to music”. If I don’t care about object names I could write: “I’m doing this on keys, above the floor, while hearing jambala”. Syntactically correct but it’s not comprehensible.

It’s important for objects to have proper names. A good name must show to a code reader its purpose and its content. So, having a collection of objects named lst or col or status variable named flag is bad because those who read the code will have to decipher how this variable is used to discover its purpose. Also, count, num, max or length are bad choices because they could mean anything. Changing that to wordCount, numDocuments, maxLength or  currentLength will give this names a meaning.

There’s a big difference between reading the code and figuring out the code.

Category: Development

Was this article helpful? Improve it with your comment.