Long variable names

RaouL picture RaouL · Jun 5, 2010 · Viewed 12.4k times · Source

Lets say i have a variable that contains the number of search engine names in a file, what would you name it?

  • number_of_seach_engine_names
  • search_engine_name_count
  • num_search_engines
  • engines
  • engine_names
  • other name?

The first name describes what the variable contains precisely, but isn't it too long?, any advice for choosing variable names? especially how to shorten a name that is too long or what kind of abbreviations to use?

Answer

Shaggy Frog picture Shaggy Frog · Jun 5, 2010

How about numEngineNames?

Choosing variable names is more art than science. You want something that doesn't take an epoch to type, but long enough to be expressive. It's a subjective balance.

Ask yourself, if someone were looking at the variable name for the first time, is it reasonably likely that person will understand its purpose?