Is there an excuse for short variable names?
31–38 of 38 posts
Re: Is there an excuse for short variable names?
#32Earlier quoted context omitted.
This actually bothered the hell out of me. For anything more complicated that highschool physics, this is terrible. You start to run out of letters and start using capitals and noncapitals, and even worse is that there are some "globals" that are not really variables but well-known constants. So you're trying to distinguish between uppercase / lowercase / variable / constant and keep all that in your head. There real…
Most people tend to get unhappy when you start dismissing their knowledge as crap . Also in this case you are wrong. With a compact notation you can think more complicated thoughts than you can with a verbose one. The downside is that a compact notation requires more from the person reading it. The tradeoff is correct, and the domain expert is not necessarily wrong. Your domain expertise is maintaining a lot of very…
For a domain expert in their domain of expertise, [long explicit names] are overhead.
Once you pass a certain threshold of complexity and/or time-investment, a well-designed program becomes its own domain of expertise. At that point there is great leverage to be had in finding a compact notation suitable for the recurring concepts of the system. In some ways, finding such a notation is how one ensures that the system has a good design and will keep it. As you point out, it (critically) is what enables us to keep more complex things in our heads. It also becomes an intimate part of the creative process – a good notation suggests new concepts and hints at how the system should grow.
Long explicit names are exactly what you don't want when it comes to the core concepts of a well-designed system. They are useful for things that aren't familiar and so need to be spelled out. But in a well-designed system, the most important concepts are familiar and it is a poor use of our limited cognitive capacity to constantly spell them out, for much the same reason that we prefer to say "gas" instead of "liquid hydrocarbons". Since cognitive capacity is our principal bottleneck in software, this is a big deal.
Re: Is there an excuse for short variable names?
#33An argument that usually lets programmers understand why physicsists do this: to a physicist variables like x (position), v (velocity), p (momentum), R (radius) are as clear as i,j,k,l to a programmer. Using the longhand would not improve readability for them, just like using arrayIndex instead of i would not improve readability for a programmer. In fact for a physicist it is much easier to read the short variable na…
and in the case the changes in energy or entropy are not so infinitesimal, the semantics of the variable name can cause all sorts of troubles
Re: Is there an excuse for short variable names?
#34Simple solution: in a program source, create a very clear comment header that won't be missed, that explains the meanings of the variables. Also, even though physicists can use any names or lengths they like in their papers, they seem to prefer concision: f = G M1 M2 / r^2 If the reader understands the math, short variable names aid comprehension, not the reverse.
you don't have to do this while you're writing the code, often-times just hammering the code out gets you something running, but then doing this after the fact really helps.
Re: Is there an excuse for short variable names?
#35Earlier quoted context omitted.
This actually bothered the hell out of me. For anything more complicated that highschool physics, this is terrible. You start to run out of letters and start using capitals and noncapitals, and even worse is that there are some "globals" that are not really variables but well-known constants. So you're trying to distinguish between uppercase / lowercase / variable / constant and keep all that in your head. There real…
Most people tend to get unhappy when you start dismissing their knowledge as crap . Also in this case you are wrong. With a compact notation you can think more complicated thoughts than you can with a verbose one. The downside is that a compact notation requires more from the person reading it. The tradeoff is correct, and the domain expert is not necessarily wrong. Your domain expertise is maintaining a lot of very…
I think your point is a very valid one. I guess when I try to read a paper that's "way over my head" academically, it's fair that the authors don't care about me.
But I don't think they know its tradeoff. The way I know this is by reading the majority of intro / mid level textbooks I've had to deal with as a freshman. At that point you're not nearly a domain expert, but the texts are written in the same way.
Re: Is there an excuse for short variable names?
#36As mentioned elsewhere in this thread, short-lived names can often be short, too. In some cases they are little more than placeholders. An example is an index for a for-loop that is in fact a "for-each" loop when the language lacks the latter and the index does not have much of a meaning of its own.