News for hackers. Stuff that matters.
Re:Is there an excuse for short variable names? by btilly on Saturday February 02, 2013 @05:00PM (#5157539)
I am reminded of a complicated piece of indexing that I had to figure out. I kept on getting confused, reversing things, etc.

Eventually I put a big comment at the top that to understand the code you needed to draw the picture, and named my variables x and y. About a page of code later, I was done. And when I has to tinker with it a couple of years later my first reaction was to wonder WTF I was thinking, wince in memory of how I had struggled with it, then I drew the picture, and I was amazed at how easy it was.

The rule is not that you need long or short variables. You need meaningful ones. A short variable name is inherently ambiguous, which can lead to confusion and mistakes. Thinking through anything with a long-variable name abuses your working memory, limiting how complex your thoughts can be.

It is a trade-off. Use the right one for your code. For me, index variables are short, and so are any variables that refer to math concepts that I understand well. Otherwise I use (concise if possible) descriptions without any abbreviation, separated by underscores.

Re:Is there an excuse for short variable names? by john_b on Saturday February 02, 2013 @05:06PM (#5157561)
A short variable name is not ambiguous when the code is based on some math or physics that has a more or less standardized notation. In this case, what's needed is to connect the variable names to the mathematics, as Rex Kerr pointed out to the OP:

"Once you understand the math, the length of the variable names is irrelevant. Do others a favor and leave a citation (in a comment) to some relevant description of the math, though, if you had to learn it!"

Re:Is there an excuse for short variable names? by btilly on Saturday February 02, 2013 @05:28PM (#5157648)
A short variable name is not ambiguous when the code is based on some math or physics that has a more or less standardized notation.

The problem is that the same notation is often used in different parts of math in different ways. You sometimes need to clarify. (Except in the case of differential geometry - there the notation is so horrible that you should find a different job! I only partly kid...)

Conversely even if you aren't using a standard math notation, meaningless names and a simple labeled diagram can often make something unambiguous in a way that no amount of verbiage in variable names can hope to do.