Posted on Thursday, February 4, 2010.
Every programmer has a variable naming philosophy. This is mine:
A name's length should not exceed its information content. For a local variable, the name
iconveys as much information as
idxand is quicker to read. Similarly,
jare a better pair of names for index variables than
index2), because they are easier to tell apart when skimming the program. Global names must convey relatively more information, because they appear in a larger variety of contexts. Even so, a short, precise name can say more than a long-winded one: compare
take_ownership. Make every name tell.
The information content metric gives a quantitative argument against long-winded names: they're simply inefficient. I internalized this metric years ago but only realized this phrasing of it recently, perhaps because I have been looking at too much Java code.