Note on naming variables

“The naming of cats is a difficult matter, it isn’t just one of your holiday games.” — T. S. Eliot

When creating named variables there are some rules that must be followed. If you violate these rules the program simply won’t allow you to save the name and you’ll have to pick a different one.

  • No cell references. If you gave the cell B3 the name ‘A1’  there would no longer be any way to refer to cell A1.
  • Do not start with a digit (0-9) or an underscore (_). Ending with one or having one in the middle is fine, as long as it couldn’t be a cell reference.

There are also a variety of specific words that are likely not to be allowed — I’ll discuss why later. ‘Max’ is one such word. Don’t panic if you’re told that your chosen name is illegal — if that’s really the best name, try ‘Max_’, but it may also be possible to make a better/more descriptive name, such as “MaxFine” or “MaxCapacity”.

In addition to the rules imposed by programs, there’s two rules I recommend following when naming variables.

  1. No spaces. I remember a time when file and directory names couldn’t have spaces in them. (Yes, I’m a dinosaur.) As far as I know, all spreadsheet programs still don’t allow them in the names of variables. However, even if someday all programs allowed it, I would still avoid spaces. Formulas can get complex, and in a complex formula it’s simply easier to read if the names aren’t broken up by spaces.
  2. Make it as long as necessary, but no longer. The longer it is, the longer any formula that uses it will get, and correspondingly harder to read. Imagine “MaxFine” versus “MaximumFine” or even “MaximumFinePerPatronPerBook”