home > resources > c++ coding standard > online version

Variable Names

Make every variable name descriptive, limit the use of abbreviations or letter-words. It's worth writing words completely since it makes the code much more readable. Beware however that when trying to find a good name, you don't end up with with something like 'the_variable_for_the_loop', use a proper English word for it like 'counter' or 'iterator'. English is a rich language and trying to find a correctly fitting word is important for code brevety, cleanness and variation. Whenever in doubt, just use an thesaurus like Merriam-Webster (http://www.m-w.com) or a rhyming dictionary like Rhyme (http://rhyme.sourceforge.net/).

Exceptions

Some standard variables are used for often recurring tasks. Below is a list of those that are accepted :

  • i : integer counter
  • it : STL-like iterator
  • <type>_it : STL-like iterator of a certain type for differentiation amongst types
  • tmp_<type> : eg. tmp_qstring, tmp_int, tmp_float for variables that are solely used for the storage of temporary intermediate values