84 points

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.

permalink
report
reply
21 points

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.

permalink
report
parent
reply
16 points

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.

permalink
report
parent
reply
13 points

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.

permalink
report
parent
reply
5 points

And even if it didn’t help my chances directly like that, even getting a small chuckle would help me be more comfortable and confident.

permalink
report
parent
reply
4 points

Honestly finding someone who can relax and intergrate into your team culture is arguably more important that anything

permalink
report
parent
reply
57 points
*

i is for index. j is simply the next letter and we’re too lazy to think up something meaningful

permalink
report
reply

jndex

permalink
report
parent
reply
5 points

kndex

permalink
report
parent
reply
3 points
*

lndex

permalink
report
parent
reply
17 points

I always thought it stood for iterator

permalink
report
parent
reply
7 points

I sometimes use it for “item”, knowing full well its established meaning as index or iterator, because I’m a rebel.

permalink
report
parent
reply
2 points

i2?

permalink
report
parent
reply
3 points

ii

permalink
report
parent
reply
2 points

This is the real answer

permalink
report
parent
reply
32 points
*

It depends. x and y are either elements or coordinates, a and b usually elements though in e.g. Haskell reserved (by convention) for type variables.

The i j k l series is reserved for indices. n m etc. are the counts of something, as such you’ll see i counting up to n. 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 i often chances are you should stop coding in C and get yourself a language with iterators. Manual loops are a bug magnet.

permalink
report
reply
5 points

It’s a shame iterators in JS are trash for memory if you have a giant array

permalink
report
parent
reply
6 points
Deleted by creator
permalink
report
parent
reply
30 points

A useful tip I picked up was to use ii instead of j for an inner loop. It’s far more distinct than j.

If for some terrible reason you have even more inner loops you can easily continue the trend i, ii, iii, iiii, iiiii - or iv, v if you’re feeling roman

permalink
report
reply
35 points

If 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.

permalink
report
parent
reply
3 points

I just do i2, i3, etc

permalink
report
parent
reply
1 point

Becomes unreadable if you’re using the iter values a lot

permalink
report
parent
reply
2 points

Two or three "i"s is readable, but any more and you’re counting.
I’Ve started using i, k, m, n that’s usually enough.

permalink
report
parent
reply
1 point

At this point we might as well go full Roman as you suggested. MXMCIIV to MXMCCVII as indices.

permalink
report
parent
reply
1 point

When you have multiple indices you’re also bound to have multiple cardinals those indices count up to, say foo.length and bar.length, so foo_i and bar_i are perfectly legible and self-documenting. A bit Hungarian but Hungarian is good in small amounts. Unless you’re dealing with width and height in which case it’s x and y but it’s not that width_i would be incomprehensible.

permalink
report
parent
reply
29 points

x is used for map, filter, etc. a and b are used for sorts, comparisons and merges. y might be used if I’m doing multiple lambda expressions (but that means I’m in a bad place already). I have no idea why, but these are firm rules in my brain.

permalink
report
reply
12 points

I’ve gotten used to using the singular form as in…

records.filter((record) => …)

Not saying this way is better but it works for me.

permalink
report
parent
reply
2 points

I do this too. I hate using just x, because it’s so non-descriptive.

permalink
report
parent
reply
1 point

Yes! I love using x (and xs) for functions over whatever the thing is (or things are).

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 6.9K

    Monthly active users

  • 1.5K

    Posts

  • 34K

    Comments