Hacker News new | ask | show | jobs
by GeneralMayhem 4039 days ago
The article is saying not to mess with the "religious" tradition of i/j/k, which means that the author actually things that ii/jj/kk are better. I don't think it's hard to follow, really, unless maybe if English isn't your first language.
1 comments

This is a weird one. Using i,j,k for loop values is fine, especially tight inner loops. I can't see that ii,jj,kk adds anything. And I don't see much point in using verbose names like innerLoopIterator or arrayIdx or whatnot for these type of variables either.

Actually later on in rule 20 he implies (with negative logic of course) that i is actually a good inner loop variable name. So that's an inconsistency right there.

ii, jj, and kk, are easier to search for (although I have jj mapped to <ESC> in vim...)

index, jndex, and kndex, are preferred, obviously.

If you have to search for loop index variable, your code has worse problems than naming.

I mean - I don't recall writing a loop longer than 2 screens in years. Usually a loop is less than half a screen long.

And anyway, you can search for [^\w]i[^\w] if you really need to.

Maybe it's aquired taste, but in array-heavy code (usually math-related) I much prefer A[i][j][k] * B[j][k][i] than the same with long names for index variables.

or \bi\b
jj = <ESC> changed my life; I'm not even joking. I even went so far as to put my zsh in vi mode and added jj there too. (WARNING: doing this will result in a pathological need to type jjk whenever you open a shell to start scrolling through history.)
I prefer mapping <ESC> to <CAPSLOCK>. Hitting single keystroke. I quickly got tired of hitting 'jj' every time I need to escape.
I personally use 'kj', which is just a natural roll from my middle to my index finger. Have you tried this?