Meaningful Variable Names

I teach a basic programming concepts class. We cover variables, data types, loops, functions, logic, and best practice techniques. I try to employ meaningful examples as much as possible to give abstract ideas value. The idea that variable names are created by the developer and can essentially be anything is sometimes hard to grasp. Beginning students feel there are specific “high tech” names that need to be used in order for a program to run successfully.

During last night’s class, we were discussing dates and times, how a language displays the information, and how to convert the information into a desired format. The students had to take military time, convert to 12 hour format and denote AM/PM. The question arose, what do the letters AM/PM stand for? One student looked up the answer – the terms are derived from the Latin language. Instead of pronouncing the words, the student said “derp a derp derp”. I went with that and named the variable for AM/PM DerpADerpDerp. As one student said “that’s the best variable name ever!”

As an extra benefit, the students had to ensure they typed it correctly each time it was referenced. I believe they got it now. For those students, we can always refer to “derp a derp derp” and know we are referring to a meaningful variable name.