On Variable Naming in Code
by Josh Staiger
December 15, 2006
Much is made of the pain of typing long variable names (or function names or class names), but code is usually read more often than it's typed. And when I'm reading code (even if it's my own), I'm grateful for names that err on the side of descriptiveness.
This means:
navigationElement
instead ofnavigation
ornav
queryString
instead ofquery
,queryStr
,string
, orstr
libraryLookupUrl
instead oflibraryLookup
orurl
The exceptions are common language idioms which any programmer could reasonably be expected to know (ie: cons in Lisp, def in Python, x as an index into array loops). These should be abbreviated as their meaning is more intrinsic and independent of the name.