r/computerscience • u/neslef3 • Dec 10 '21
Why do computer scientists (and mathematicians) use the worst variable names in proofs and papers?!?
Sorry if this post doesn’t quite fit this sub but this has been bothering me for ages and I’ve recently hit a breaking point for my frustration.
It just pisses me off that there are 26 letters in the alphabet and 325 pairs of letters you can choose and for some reason the pair that we all seem to use is (i,j).
There are literally no two letters that look more alike and that could get more easily mixed up but for some reason whether it be in code are in my case here in proofs and papers these two letters are always used together.
Why should I have to use a magnifying glass to read a damn proof from a paper that couldn’t have the decency to at least use a better font?
And it doesn’t stop at (i,j). We also love to use (m,n), (p,q), (u,v).
Like I get it, it’s more clear that the variables are related when they look alike, but it should certainly be more important that people don’t mix them up???
195
u/Le_7r011 Dec 10 '21
You have inspired me. From now on I’m gonna use combinations of the letter i, j and l for my variables.
55
9
14
u/RadiantHC Dec 10 '21
0
u/sneakpeekbot Dec 10 '21
Here's a sneak peek of /r/foundsatan using the top posts of the year!
#1: ’ | 18 comments
#2: I guess i won't go hiking for a while | 42 comments
#3: Airpods | 18 commentsI'm a bot, beep boop | Downvote to remove | Contact | Info | Opt-out | Source
73
u/linuxlizard Dec 10 '21
Pull up a chair, young'ens, and hear about the old timey language FORTRAN. Back in FORTRAN, variables were implicitly typed based on the first letter of their name. Start your variable with letters between 'i' and 'n' and it would be an integer. Outside that range, it would be a float (if I remember correctly). Why 'i' and 'n' ? Because some clever language designer decided 'integer' thus the 'i' and 'n'. Using i and j as loop variables started from there (in the 60s and 70s, probably) and has continued on ever since.
27
u/linuxlizard Dec 10 '21
FORTRAN still used today, by the way. Is very important in numerical computing. Because of some quirks in the language design, FORTRAN compilers can generate some of the fastest code (faster than C). https://en.wikipedia.org/wiki/Fortran#Science_and_engineering
8
Dec 10 '21
Neat edge case.
8
u/FrAxl93 Dec 10 '21
I believe numpy has some Fortran source for the fast mathematics, so not really edge case.
1
Dec 10 '21
Well, in all fairness though, unless you're specifically modifying the Fortran code, you can use more user-readable variable names.
2
u/FrAxl93 Dec 11 '21
I was just answering about the fact that Fortran is still used today in a iper used library. Of course using numpy doesn't require using Fortran (thank god) but just because it's under the hood it does not mean it's a super edge case.
1
u/proverbialbunny Data Scientist Dec 11 '21
fwiw, this is no longer the case, but there is still a lot of legacy FORTRAN out there.
2
u/linuxlizard Dec 11 '21
Yeah, even back when I was first learning FORTRAN (long long ago), our instructor emphasized 'implicit none' to turn off that auto-variable nonsense.
1
u/squidgyhead Dec 11 '21
Fortran is not faster than C. For numerical stuff, both are basically equivalent. The only real difference that I have been able to find is for recursive functions, where Fortran is much slower.
A lot of fast code has been written in Fortran, and it will remain important I'm scientific computing, but it isn't a unicorn.
1
u/AnnualDegree99 Dec 11 '21
some of the fastest code (faster than C)
smiling in assembly
Look I might want to explode every time I look at any x86 assembly, but damn is it fast.
1
Dec 11 '21
What is it about those quirks that make it so fast? Why don't we use those quirks in the design of new languages to make them faster?
1
u/linuxlizard Dec 11 '21
Disclaimer: I'm not a compiler expert. This is just what I understand from reading over the years.
FORTRAN is a very simple language. It's in fact the first compiled "high level" computer language. The name FORTRAN comes from "Formula Translation" and originally it was just a simple way to write math. The problem with, for example C, is some of C's rules prevent super optimization of code. The one I understand that causes the most problems is aliasing. https://en.wikipedia.org/wiki/Aliasing_(computing)
If the same memory location can be represented by multiple variables, then the compiler has to assume worst case and cannot optimize certain paths. If the language doesn't allow such flexibility, then the compiler can crack its knuckles and go to town on optimization.
(Lots of hand waving here, sorry. It's been a long, long time since compilers class!)
1
Dec 11 '21
That's actually a really good explanation and a good starting point for my investigation. I'll look in to that more, thanks!
14
4
u/psharpep Dec 10 '21
Oh noooo... Somehow it feels like every day I learn a new fun fact about old-school Fortran that makes me gag haha
4
u/larenspear Dec 10 '21
IMPLICIT NONE!!! One of the first things I learned about when I was learning Fortran.
2
u/linuxlizard Dec 11 '21
Indeed. We had 'implicit none' hammered into us when I as learning FORTRAN. Woe be to those who had to maintain enormous libraries of older FORTRAN.
3
2
u/Struppigel Dec 11 '21
Fotran was created by mathematicians. This notation using i,j as indices was there before Fortran was invented.
36
u/anras2 Dec 10 '21
The worst is when a student/professor, or anyone really, writes handwritten m and n in sloppy cursive.
8
3
30
u/AddemF Dec 10 '21
We keep using (i,j) because it is evocative of all the other times we used (i,j). We reuse them precisely so that it's like all the other times we used them, so that you can see it in a glance and have a sense of what it means. We use x when we mean an unknown real number or a variable of a real number, we use z when it's an unknown complex number. It's really helpful to quickly understand something, when we reuse these names. I would find a text nauseating if it didn't use this orienting technique.
2
8
u/notasuccessstory Dec 10 '21
I think OPs argument is against certain typefaces and fonts in which the two letters (i,j) can appear identical on initial glance. Some people are more prone to this than others due to a variety of reasons.
7
13
u/V0ldek Dec 10 '21
Complain to whoever came up with the alphabet, all those pairs are letters next to each other and that's why they're used like this.
'i' is index, 'n' is number (or natural), 'v' is vector or vertex.
4
u/crouchingarmadillo Dec 10 '21
I just like to use letters that are close to each other, because it’s easier for me than coming up with another name. Sometimes I’ll even use a,b,c for indices. But if I’m not working with complex numbers, I often use i because it’s easy to remember i = index. And after that comes j,k,l.
4
Dec 10 '21
Convention, mostly. I can see good, descriptive variable names being useful, but convention will almost always win out in math/compsci.
None of us want to incur the wrath of our professors, and I know professors that would be instantly annoyed at using something less conventional.
4
u/UnendingResolve Dec 10 '21
The i is mostly a convention for [i]terators, I guess the J was the logical follow-up people thought of when they started this trend. I for one only use i in very concise and simples loops/iterations, otherwise short and descriptive names make more readable code / math problems.
1
u/WiggWamm Dec 10 '21
I think it’s because you have to take the index of things a lot, but it’s shorter to type i instead of index. And then it just went to j after then and so on and so forth
1
u/Equivalent-Map-8772 Dec 10 '21
It’s mostly for convention. Picking alphabetically close variable names for variables that are related to each other is just common sense. It feels and reads weird, and gets confusing really fast, when you have a group of variables that are related but they all use arbitrary names. Even more so when the proof is several pages long and then you have to remember at each step what each individual variable does/is.
So, if you pick i for something because it reminds you of index, iterator, image, etc. the logical follow up is to pick j after and not ξ, Ω, z, or “mojito”.
1
u/fatrat_89 Dec 10 '21
Not sure about all of the common ones but I believe that "i" is typically shorthand for "iteration"? At least that's the impression I got and why I use it. Also "n" is just shorthand for "number", so that's what I use as the input number for a function that then gets calculated in various ways.
Some don't make sense to me, like the connection weights in artificial neuron functions are typically a "g", and I'm not really sure why.
1
1
u/meat_sandwich80 Dec 10 '21
From now on I’m just going to use 39 i’s in a row as a variable to represent row index and 40 to represent column index
1
u/cincuentaanos Dec 10 '21
i = iterator
j = next letter in the alphabet, if you've already used i as an iterator, same as k etc.
It really does make some amount of sense.
1
1
Dec 11 '21
felt this way starting algebra as I always thought multiplication was the 'x' symbol I asked why the hell would they make 'x' different
1
u/Feb2020Acc Dec 11 '21 edited Dec 11 '21
I find it simple.
i, j, k for loops
m, n for matrix dimensions
p, q for probabilities
u, v for random variables
The point is, they are almost exclusively used as throwaway variables (index, dimensions, temporary, etc.). It’s very easy to understand what arr(i,j,k) means. arr(row,col,depth) isn’t as easy on the eyes. Also, there are languages where row and col may be reserved for functions.
In some languages, i refers to complex numbers so some people use ii instead to distinguish the i complex number from the ii variable.
1
u/SingularCheese Dec 11 '21
Some fields of math likes to use character set to denote type, so you will have vector v in one vector space being projected into vector ν (Greek letter nu) in another vector space. Physics likes to do the same thing too with v and nu being the velocity of some object in different frames of reference. It's because all those academics don't need to maintain a code base over two decades of enhancements and bug-fixing.
1
1
u/bill_klondike Dec 11 '21
LOL. OP complaining about i, j, k has clearly never encountered ξ in the wild.
1
1
Dec 11 '21
I feel this also depends on the context. Like, you see those kinds of variables in proofs and in papers because the target audience is people who are interested/working in the field and so they know what they represent and they can make sense out of very quickly. It just gets straight to the point you know.
But then if you are say teaching to kids, then using variables like i, j is not helpful. They should be more meaningful and much more clearer. Like, forced documentation in a way. This allows less confusion and makes it easier for kids to understand for instance.
But I am with you. I tend to have long variable names because it's just so much more clearer to me when I am coding. And for anyone reading the code as well. Yes, it can clutter but there are times when it's helpful to have long names for certain code snippets. Not for everything but for some.
1
1
1
1
u/Lightning_Bee Dec 11 '21
Im pretty sure i is short for index and j is just the next letter. n is short for number and m is just the next letter and p is short for prime and q is just the next letter
1
1
u/aunluckyevent1 Dec 11 '21
well matematician are a weird bunch, but every human being is not exempt. let them have their convention. as a programmer i learned that different lingo and conventions are used in each work environment so it's really not only a problem of mathematics.
i'm all for longer and auto documenting variables, but it's always a failed crusade from the start.
1
Dec 11 '21
I study quite a bit of mathematics. I see (u,v), (m,n), (I,j), (alpha,beta) - and more - all over the place.
1
u/DaveAstator2020 Dec 11 '21
I prefer to choose these I,k,n t,p Also a,b,c in some cases. Because they are distinguishable. And just avoid mirrored or cloned letters all together. No q,m,j (especially fuck j). Also im annoyed by people who use single letters T,U,V For generic parameter names. Hope they burn in hell.
1
u/w3woody Dec 11 '21
Now I want to use greek letters for my variable names. (Swift permits this.)
Can you imagine something like:
for ι in Α {
...
}Better yet, Swift allows custom operators to be defined, which means I now want ∈ to be defined as a binary operator to perform a 'set contains' operation.
1
1
0
Dec 10 '21
[deleted]
5
u/neslef3 Dec 10 '21
See page 6/30 (or 262) top of the right column of this paper I was just reading (a printed version of).
Not sure how to attach a screenshot of it without too much effort.
0
98
u/[deleted] Dec 10 '21
It’s from math notation where i,j refer to rows and columns. There’s no real reason it continues except that’s how people come to learn the notation and people stick with what they know