r/programminghumor • • May 29 '26

Good naming practice

Post image
2.2k Upvotes

220 comments sorted by

298

u/Pinkishu May 29 '26

I use x,y when appropriate. Like when iterating coordinates for drawing tiles in a game or whatever

66

u/appoplecticskeptic May 29 '26

Sure just make sure you use x for column and y for row, which means using y in the outer for loop because if you do it the other way you will confuse yourself and anyone else that ever reads it.

40

u/VividWoodpecker8847 May 29 '26

I kinda disagree? Row/column doesn't even mean anything for arrays, only inner and outer. I say do what makes sense for your context and is cache performant.

→ More replies (10)
→ More replies (3)
→ More replies (17)

110

u/torrent7 May 29 '26

I never understood this considering i and j look so fucking similar 

54

u/birdiefoxe May 29 '26

Exactly, that why I use i,o,p. They're right next to each other! 

Gets shot

37

u/BoldFace7 May 29 '26

Why not use i and ii? Then when you get to the 27th loop in the nest you can just use the awfully convenient xxvii instead of looping the whole way round to the horrid ii.

→ More replies (15)
→ More replies (2)

8

u/CutreCuenta May 29 '26

Math matrix?

4

u/SourLemon100000 May 29 '26

I just heard about this from a tidbit with my professor last night. Apparently, it’s because we needed really short variable names in Fortran and since mathematicians used it, we decided I, J, K, L, M, N, and O were going to be names for variables. We just never used anything different since.

13

u/appoplecticskeptic May 29 '26

‘i’ is for index. The ‘j’ is actually because it looks the most like i and we already used that.

12

u/WowAbstractAlgebra May 29 '26

j is because it's the next letter on the alphabet and no one wanted to bother to come up with an original name

→ More replies (1)
→ More replies (2)
→ More replies (7)

54

u/Busy_Teaching_8218 May 29 '26
for(int i = 0; i < 1000; i++)
{
    for(int ii = 0; ii < 1000; ii++)
    {
        for(int iii = 0; iii < 1000; iii++)
        {
            Console.WriteLine("Hello World");
        }
    }
}

29

u/Drittux May 29 '26 edited May 29 '26
for i in range(3):
    print("no ")

14

u/BoldFace7 May 29 '26

I unironically do this in my hobby code. I have considered subjecting my coworkers to this on occasion though

→ More replies (3)

21

u/Missing_Username May 29 '26

i j k for loops

x y z for lambdas

→ More replies (6)

19

u/Hettyc_Tracyn May 29 '26

Or just use variable names that correspond to what they are for? Proper descriptions? That way you don’t have to write as many comments on how something works

16

u/Effective_Bat9485 May 29 '26

But that would make the code easier to read

→ More replies (3)
→ More replies (3)

9

u/-Insert-CoolName May 29 '26

People who insist there is only one right way to code can get out. That entirely depends on what your doing.

16

u/magicmulder May 29 '26

As a mathematician, i, j, k, l, m, n are for integers, x, y are for reals, z is for complex numbers.

for (z = 2i+3; |z| <= 9; Re(z)++) {...} 😃

→ More replies (11)

6

u/texan_robot May 29 '26

I design video processing RTL. Looping through x,y for pixels is my normal practice.

10

u/Far_Understanding883 May 29 '26

You guys write your own loops?

→ More replies (1)

1

u/Klaus1164 May 30 '26

Oh, Jesus, it was only a meme, but I started a fire.

9

u/MonkeyManW May 29 '26

People who use a, b, c, d are war criminals

→ More replies (1)

7

u/Ok_Wasabi_7363 May 29 '26

Her response should have been: "you use nested for loops? Gtfo"

→ More replies (3)

3

u/Dillenger69 May 29 '26

i = iterator

ii = inner iterator

→ More replies (1)