News for hackers. Stuff that matters.
Re:Clarity over brevity in variable and method names by Silhouette on Monday September 10, 2012 @03:01PM (#4501504)
I usually find that the wider the scope of a variable or function, the longer and more descriptive the name I want to use. For names that are only used locally, there's more context available, and the name can be shorter to keep the code more concise and easily scannable.

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

    y = m * x + c,
as long as the terminology/notation is standardised or well understood. I don't think writing

    dependent_variable = gradient * independent_variable + crossing_point
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.

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.