Re:Clarity over brevity in variable and method names
by pjungwir on Monday September 10, 2012 @04:46PM
(#4502158)
I first read this principle in some Java coding guidelines published by Sun, and I think it's great advice. Anything public probably deserves a longer name, keeping local variables short promotes readability.
For example, I might call a function in a geometry library gradient_of_line, but within a line module in that library, I'd probably just call it gradient.
In mathematical code where there is a common notation that happens to be very concise, I'm quite happy writing code that uses it, like
as long as the terminology/notation is standardised or well understood. I don't think writing is an improvement in this sort of case.By a similar argument, I have no problem with giving abstract loop control variables like counters a short name like i or n, since they are only used within a small area of the code. However, if the variable represents some more meaningful concept, then I would probably name it accordingly.