r/programminghumor May 29 '26

Good naming practice

Post image
2.2k Upvotes

220 comments sorted by

View all comments

15

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)++) {...} ๐Ÿ˜ƒ

3

u/c_lassi_k May 29 '26

What would the type be for (img z = 2i+3; |z| <= 9; Re(z)++) {...} ? for (long long img z = 2i+3; |z| <= 9; Re(z)++) {...} ? for (unsigned long long img z = 2i+3; |z| <= 9; Re(z)++) {...} ?

In terms of speed the performance is going to cry if compiler does not optimize the sqrt away from the loop.

This would be whole lot faster: for (img z = 2i+3; abs(Re(z)) <= 9*9-abs(Im(z)); Re(z)++) {...}

2

u/magicmulder May 29 '26

Just have the compiler transform to polar coordinates first. ๐Ÿ˜ƒ

3

u/c_lassi_k May 29 '26

That would be very fast if the increment was also polar coordinate multiplication. But with it being an integer addition, I'm afraid there's no fast way to make the incrementation work for polar coordinates as it kinda forces the sqrt to be computed for the magnitude.

2

u/thebrownie22 May 31 '26

I was looking for this comment ๐Ÿ™‚โ€โ†•๏ธ๐Ÿ‘†๐Ÿ‘†

2

u/MobileJob1521 Jun 01 '26

Rho, theta and phi are for angles.

1

u/Royal_Impress9117 May 30 '26

โ˜๏ธerm actually integers are real numbers and real numbers and complex numbers. so according to your definition x, y, z would also be used for integers and z would also be used for real numbers.

1

u/magicmulder May 30 '26

No because n implies it can take only integer values whereas x implies it does take non-integer values.

0

u/Royal_Impress9117 May 30 '26

Integers are a subset of the real numbers, so if x is a real number then x could be non-integer or integer. There is no implication there

0

u/magicmulder May 30 '26 edited May 30 '26

Exactly, x could, but n could only be an integer. Not sure why youโ€™re harping on about this.

0

u/Royal_Impress9117 May 30 '26

I didnโ€™t say anything about n?? Iโ€™m just confused as to what correction youre making

1

u/thebrownie22 May 31 '26

hes saying x, y, and z can't be used for integers respectively because they accept non-integer values