News for hackers. Stuff that matters.
Re:Adobe Photoshop 1.0 Source Code (2013) by DanHulton on Tuesday December 23, 2025 @11:13AM (#46366476)
Xyz makes sense because that is what those axes are literally labeled, but ijk I will rail against until I die.

There's no context in those names to help you understand them, you have to look at the code surrounding it. And even the most well-intentioned, small loops with obvious context right next to it can over time grow and add additional index counters until your obvious little index counter is utterly opaque without reading a dozen extra lines to understand it.

(And i and j? Which look so similar at a glance? Never. Never!)

Re:Adobe Photoshop 1.0 Source Code (2013) by jonahx on Tuesday December 23, 2025 @12:07PM (#46366987)
> but ijk I will rail against until I die.

> There's no context in those names to help you understand them, you have to look at the code surrounding it.

Hard disagree. Using "meaningful" index names is a distracting anti-pattern, for the vast majority of loops. The index is a meaningless structural reference -- the standard names allow the programmer to (correctly) gloss over it. To bring the point home, such loops could often (in theory, if not in practice, depending on the language) be rewritten as maps, where the index reference vanishes altogether.

Re:Adobe Photoshop 1.0 Source Code (2013) by vilos1611 on Tuesday December 23, 2025 @12:22PM (#46367116)
I respectfully disagree.

The issue isn't the names themselves, it's the locality of information. In a 3-deep nested loop, i, j, k forces the reader to maintain a mental stack trace of the entire block. If I have to scroll up to the for clause to remember which dimension k refers to, the abstraction has failed.

Meaningful names like row, col, cell transform structural boilerplate into self-documenting logic. ijk may be standard in math-heavy code, but in most production code bases, optimizing for a 'low-context' reader is not an anti-pattern.

Re:Adobe Photoshop 1.0 Source Code (2013) by jonahx on Tuesday December 23, 2025 @12:32PM (#46367214)
If the loop is so big it's scrollable, sure use row, col, etc.

That was my "vast majority" qualifier.

For most short or medium sized loops, though, renaming "i" to something "meaningful" can harm readability. And I don't buy the defensive programming argument that you should do it anyway because the loop "might grow bigger someday". If it does, you can consider updating the names then. It's not hard -- they're hyper local variables.

Re:Adobe Photoshop 1.0 Source Code (2013) by vilos1611 on Tuesday December 23, 2025 @01:02PM (#46367506)
In a single-level loop, i is just an offset. I agree that depending on the context (maybe even for the vast majority of for loops like you're suggesting) it's probably fine.

But once you nest three deep (as in the example that kicked off this thread), you're defining a coordinate space. Even in a 10-line block, i, j, k forces the reader to manually map those letters back to their axes. If I see grid[j][i][k], is that a bug or a deliberate transposition? I shouldn't have to look at the for clause to find out.

Re:Adobe Photoshop 1.0 Source Code (2013) by ori_b on Tuesday December 23, 2025 @04:10PM (#46369498)
If you see grid[y][z][x], is it a bug or a deliberate transposition?
Re:Adobe Photoshop 1.0 Source Code (2013) by kaibee on Tuesday December 23, 2025 @11:23AM (#46366581)
ijk are standard in linear algebra for vector components.

> (And i and j? Which look so similar at a glance? Never. Never!)

This I agree with.

Re:Adobe Photoshop 1.0 Source Code (2013) by eimrine on Tuesday December 23, 2025 @02:23PM (#46368433)
What if not ijk? I know only uvw.
Re:Adobe Photoshop 1.0 Source Code (2013) by jiggawatts on Tuesday December 23, 2025 @02:39PM (#46368598)
Pretend to be a physicist and use μ and ν.
Re:Adobe Photoshop 1.0 Source Code (2013) by zeckalpha on Tuesday December 23, 2025 @05:55PM (#46370460)
i came from imaginary numbers which were extended to make quaternions.
Re:Adobe Photoshop 1.0 Source Code (2013) by jibal on Tuesday December 23, 2025 @07:20PM (#46371075)
i, j, k comes from FORTRAN's implicit types -- by default, names starting with I-N are integers and all other names are real.
Re:Adobe Photoshop 1.0 Source Code (2013) by jcelerier on Tuesday December 23, 2025 @07:41PM (#46371204)
this is much older ; Joseph Fourier was already using "i" and "j" for indices in the 1800s. See page 209: https://www.google.ca/books/edition/OEuvres_de_Fourier_Th%C3...
Re:Adobe Photoshop 1.0 Source Code (2013) by jibal on Tuesday December 23, 2025 @08:33PM (#46371508)
The context is i, j, k as indices in programs. No doubt FORTRAN was influenced by prior use such as you cite. But in no case does i used as an index come from i designating an imaginary number, which is what I aimed to refute.
Re:Adobe Photoshop 1.0 Source Code (2013) by zeckalpha on Wednesday December 24, 2025 @08:03PM (#46381117)
Representing dimensions as indexable rows and columns of vectors or matrices was done on paper in the 1800s.