Is there an excuse for short variable names?
programmers.stackexchange.com
Is there an excuse for short variable names?
1–10 of 38 posts
Re: Is there an excuse for short variable names?
#2 //for every
for(int i = 0; i Re: Is there an excuse for short variable names?
#3//for every for(int i = 0; i
di[ctrl+space] = Math.Sq[ctrl+space](xD+[ctrl+space]
... robo[ctrl+space][index].ohG[ctrl+space]
Every editor I've used in about 10 years has had an excellent autocomplete feature. I've never had to type out such long variable names.Re: Is there an excuse for short variable names?
#4//for every for(int i = 0; i
di[ctrl+space] = Math.Sq[ctrl+space](xD+[ctrl+space] ... robo[ctrl+space][index].ohG[ctrl+space] Every editor I've used in about 10 years has had an excellent autocomplete feature. I've never had to type out such long variable names.
Re: Is there an excuse for short variable names?
#5//for every for(int i = 0; i
di[ctrl+space] = Math.Sq[ctrl+space](xD+[ctrl+space] ... robo[ctrl+space][index].ohG[ctrl+space] Every editor I've used in about 10 years has had an excellent autocomplete feature. I've never had to type out such long variable names.
Re: Is there an excuse for short variable names?
#6http://37signals.com/svn/posts/3250-clarity-over-brevity-in-...
Re: Is there an excuse for short variable names?
#7Earlier quoted context omitted.
di[ctrl+space] = Math.Sq[ctrl+space](xD+[ctrl+space] ... robo[ctrl+space][index].ohG[ctrl+space] Every editor I've used in about 10 years has had an excellent autocomplete feature. I've never had to type out such long variable names.
Reading is arguably more important than typing. Being able to fit more code on the screen has its advantages, too.
Re: Is there an excuse for short variable names?
#8Also, 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.
Re: Is there an excuse for short variable names?
#9Eventually 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?
#10I 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 me…
"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!"