News for hackers. Stuff that matters.
Re:Top Things That Annoy Programmers by anatoly on Monday March 15, 2010 @08:21PM (#1194552)
Surely there's nothing wrong with single-character variable names, used appropriately.
Re:Top Things That Annoy Programmers by aasarava on Monday March 15, 2010 @11:16PM (#1194844)
What's an example of an appropriate single-char variable name, in your opinion?
Re:Top Things That Annoy Programmers by anatoly on Tuesday March 16, 2010 @07:03AM (#1195424)
i,j, sometimes n. When working with coordinates - x, y, z.
Re:Top Things That Annoy Programmers by roundsquare on Tuesday March 16, 2010 @01:42AM (#1195122)
If you are working in finance, you might use common single letter variables, for example if you are creating a black-scholes function. E.g. r = interest rate, etc...
Re:Top Things That Annoy Programmers by wglb on Sunday April 04, 2010 @10:28PM (#1241222)
Better to use 'rate' or 'irate'.
Re:Top Things That Annoy Programmers by damovisa on Monday March 15, 2010 @11:25PM (#1194859)
personally, I find this more than ok:

for (int i=0; i<items.length; i++) { //do something small with items[i] }

Re:Top Things That Annoy Programmers by cema on Monday March 15, 2010 @11:53PM (#1194917)
Correct!

However, I should confess that I usually write it as ii:

  for (int ii = 0; ii < items.length; ii++) ...
Re:Top Things That Annoy Programmers by jrockway on Tuesday March 16, 2010 @02:36AM (#1195186)
Why?
Re:Top Things That Annoy Programmers by MaMa on Tuesday March 16, 2010 @07:15AM (#1195440)
Then it's not a single character variable name anymore
Re:Top Things That Annoy Programmers by Silhouette on Tuesday March 16, 2010 @11:35AM (#1195906)
It gives you something you can quickly search for: hit <incremental search keyboard shortcut> followed by "i" twice and you're there. Do the same with a single-character name, and you hit any time that character appears anywhere.

I personally find the doubling awkward, and with modern editors I use semantic searching much more than raw text scans so the benefit of doubling is marginal, but there is at least one sensible reason you might choose to do it.

Re:Top Things That Annoy Programmers by jrockway on Tuesday March 16, 2010 @08:41PM (#1197301)
Or you could just search for "i =" or "int i" or "for"?
Re:Top Things That Annoy Programmers by Silhouette on Tuesday March 16, 2010 @11:49PM (#1197699)
Sure you could, but while you're busy trying to find the exact combination of spacing and punctuation that starts the loop you want, and then manually looking through the loop to find every further reference to the same variable, the guy who called it "ii" and found it with the first four keystrokes is already being productive.

As I said before, it's probably not as useful with modern IDEs that have semantic search capabilities, but there is a genuine reason some people prefer the "ii" style.

Re:Top Things That Annoy Programmers by jasonkester on Monday March 15, 2010 @11:30PM (#1194864)
i
Re:Top Things That Annoy Programmers by jrockway on Tuesday March 16, 2010 @02:35AM (#1195185)
x, as in "f x = x + 2". What else are you going to call it? "addend"?
Re:Top Things That Annoy Programmers by Xichekolas on Sunday March 21, 2010 @02:52PM (#1208358)
f = (+ 2)

(I'm not a huge fan of point-free, I'm just being facetious ;)