When I’m doing coding interviews I always like to start off and say I’m a big fan of very long variable names. “As descriptive as you can be” I say. Then I get to my first for loop. Instead of i I use “iterator” and then when I start a nested loop I use “jiterator” and it always gets a laugh.
I used to conduct coding interviews at my old job. If someone came in and had some humor like that, it would be big bonus points in my book. Being someone I would like to be on a team with is very important. Plus, I think it shows confidence and being comfortable in situations that make most people nervous.
I’ve been at two start ups and they had me interview people. Honestly this is what I looked for. I’d ask basic questions to prove you had an idea about coding, but I can teach someone to code, I can’t teach someone to be someone I like working with.
You can teach them to code if there is an underlying level of logic to build off. I’ve met a few people in life who I know for a fact will never code, no matter how smart they generally are.
i is for index. j is simply the next letter and we’re too lazy to think up something meaningful
jndex
kndex
lndex
I always thought it stood for iterator
I sometimes use it for “item”, knowing full well its established meaning as index or iterator, because I’m a rebel.
It depends.
xandyare either elements or coordinates,aandbusually elements though in e.g. Haskell reserved (by convention) for type variables.The
ijklseries is reserved for indices.nmetc. are the counts of something, as such you’ll seeicounting up ton. Both are due to mathematical sum notation and general mathematical convention. Random google result:Let x1, x2, x3, …xn denote a set of n numbers. x1 is the first number in the set. xi represents the ith number in the set.
…if you’re using a language in which you use
ioften chances are you should stop coding in C and get yourself a language with iterators. Manual loops are a bug magnet.It’s my understanding that i,j are conventionally used in mathematics which carried over into programming, but specifically it comes from Fortran in which all integer variables start with “I” through “N” based on said mathematical convention
In fact this goes all the way back to Hamilton when he invented quaternion, in which i,j,k are used as basis vectors (which are generalizations of the imaginary i). Later Gibbs dropped the scalar component and gave us the modern vector.
In old FORTAN variable starting with I…N are integers. This is how the practice began.
Oh wow, I thought it was because “i” was a short way of writing “index”. Then “j” was just logical after that.
You are still correct! The letters I & n are the first letters on Index.
I used starcraft references in mine till the project lead demanded I knock it off.
The protoss quotes were perfect.
don’t mind
ibut personally always useindexorx, y, zfor gamesdeleted by creator
People who name iterators with one letter have no soul.
And people who iterate over 3D space using firstDimensionIndex, secondDimensionIndex, and thirdDimensionIndex instead of x, y, z have no sense 😜
x, y, and z are absolutely fine for spatial addressing.
A useful tip I picked up was to use
iiinstead ofjfor an inner loop. It’s far more distinct thanj.If for some terrible reason you have even more inner loops you can easily continue the trend
i,ii,iii,iiii,iiiii- oriv,vif you’re feeling romanIf you have the need to nest 5 levels of for-loops, I suggest taking a step back and rethinking your approach, my friend.
Even if that other approach is just refactoring it into separate methods.
When you have multiple indices you’re also bound to have multiple cardinals those indices count up to, say
foo.lengthandbar.length, sofoo_iandbar_iare perfectly legible and self-documenting. A bit Hungarian but Hungarian is good in small amounts. Unless you’re dealing withwidthandheightin which case it’sxandybut it’s not thatwidth_iwould be incomprehensible.







