3 ms·
I don't mind "i", but if there's an inner loop with "j" as well, you are BEGGING for confusion.
by DanHulton 4y ago
I don't mind "i", but if there's an inner loop with "j" as well, you are BEGGING for confusion.
- PeterisP 4y agoOften "i" and "j" would appear when the code is the implementation of some math formula which would idiomatically use "i" and "j" when written 'properly' on paper or LaTeX.
- samsquire 4y agoI got down to "k" too. What about "x" and "y"? One important consideration of nested loops is row major access pattern rather than column major pattern, so access array[i][j] rather than array[j][i] due to the data locality of each. You shall get a performance boost by accessing them in that order. I worked on parallelizing nested loops across OS threads and load balancing between outer loops for different progressions through the loop. I also wrote some code to reverse the loop direction to avoid a cache miss when the indexes go back to 0. https://github.com/samsquire/multiversion-concurrency-control#concurrent-loop-concurrentloopjava-and-tickpy https://github.com/samsquire/multiversion-concurrency-contro...
- DanHulton 4y ago`x` and `y` are also problematic, though slightly less so. The biggest issue I have is that they're similar in appearance. `abc` is much better, because they're clearly different from each other, if you're married to single-letter values. `i` and `j` are usually indicative an index for something, and indicating what you're indexing makes the code clearer to read and easier to maintain. `idxUsers`, `idxPosts`, for example. `x` and `y` are a bit trickier because they're very frequently the canonical positional co-ordinates, and renaming them can actually make it _harder_ to read, so (like all things in naming) is a real judgment call, but frequently can be replaced with `col` and `row`, which, to me reads _much_ clearer, especially when using row-major access pattern: `array[row][col]`.