Hacker News new | ask | show | jobs
by cema 5943 days ago
Correct!

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

  for (int ii = 0; ii < items.length; ii++) ...
1 comments

Why?
Then it's not a single character variable name anymore
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.

Or you could just search for "i =" or "int i" or "for"?
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.