Fortran, really.
In Fortran, variables beginning with the letters i
through n
have integer type by default, whereas all other letters imply a real-number (floating-point) variable. You can change this by declaring a type, but using i
for a real is non-obvious.
(Hence the old joke, “God is real — unless declared integer.”)
idk, this arbitrary i-n range behaving differently than other variables sounds like a terrible source of weird bugs to me. I don’t think variable names should ever change a program’s behavior.
edit:
Many old Fortran 77 programs uses these implicit rules, but you should not! The probability of errors in your program grows dramatically if you do not consistently declare your variables.
in programming, and in mathematics, it’s always been weird to me that frequently paired variables are basically the most easily confused for one another pairs, especially when written quickly or sloppily.
- i and j
- x and y
- m and n
exactly, this is so annoying. I don’t know by first-hand experience, but I also think p
and q
are confusing for dyslexic people.
i knew i was forgetting some other common pairings, thank you. p/q and u/v always bugged me too.
u and v were so difficult for me to differentiate in handwriting. My handwriting is not that pretty and the difference between a round bottom and a sharp bottom is not that big when stressed in an exam.
i for index or iteration. Using j, k, l… in loops signals (imho) that there is most likely an outer loop and the one using j, k, l are nested. x and y of course are carthesian coordinates . n is used as amount of substance in SI-unit-system, m is mass, maybe thats why it is used as amount of items in a set (Menge).
Programming computers have started to solve mathematical problems and math already used these symbols for centuries(?), so why you should change them? They are well established even in simple school mathematics. And at the end of the day a computer is nothing more than a calculator.
Usually variables like that can be avoided with itterators nowadays. If they can’t I like to use idx
, if they are nested I name them after what they index, like idx_rows, idx_cols
.