• Sam@sh.itjust.works
    link
    fedilink
    arrow-up
    14
    ·
    1 year ago

    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.

    • Dandroid@dandroid.app
      link
      fedilink
      arrow-up
      5
      ·
      1 year ago

      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.

      • Hazama@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        1 year ago

        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.

        • KairuByte@lemmy.world
          link
          fedilink
          arrow-up
          5
          arrow-down
          1
          ·
          1 year ago

          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.

      • Sam@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        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.

  • barsoap@lemm.ee
    link
    fedilink
    arrow-up
    14
    ·
    edit-2
    1 year ago

    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.

  • Poob@lemmy.ca
    link
    fedilink
    arrow-up
    14
    arrow-down
    1
    ·
    edit-2
    1 year ago

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

    • pazukaza@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Oh wow, I thought it was because “i” was a short way of writing “index”. Then “j” was just logical after that.

    • emptyother@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Learned that VERY recently from here, at NDC Oslo 2023, he mentioned it around 42:54. The whole talk is worth watching, its about the history of javascript all the way back to FORTRAN (the talk itself starts at 25:03).

  • TeoTwawki@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 year ago

    I used starcraft references in mine till the project lead demanded I knock it off.

    The protoss quotes were perfect.

  • StudioLE@programming.dev
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    1 year ago

    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

    • hstde@lemmy.fmhy.ml
      link
      fedilink
      arrow-up
      7
      ·
      1 year ago

      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.

    • barsoap@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      11 months ago

      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.

    • catfish@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      And people who iterate over 3D space using firstDimensionIndex, secondDimensionIndex, and thirdDimensionIndex instead of x, y, z have no sense 😜

  • Cowabunghole@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    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

    • galilette@mander.xyz
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 year ago

      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.

  • dark_stang@beehaw.org
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    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.

    • DogMuffins@discuss.tchncs.de
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      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.

  • Spzi@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    I find it hard to read when these are together:

    • i, j, l
    • n, m, u, v, w

    From all the possible character combinations, somehow the lookalike combinations are among the most popular. Yes, probably comes from math. I hated it even more when my math prof’s i and j on the board were indistinguishable.

    • spauldo@lemmy.ml
      cake
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      When the practice started, most (if not all) programming languages used capital letters. IIRC the computers that ran early FORTRAN (which is where the I,J,K, etc. convention comes from) didn’t even support lower case letters.

  • Bilb!@lem.monster
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    1 year ago

    WTF, I have never used nor seen “j.”

    I don’t usually have to name these variables these days though. Pretty much everything I use has foreach or some functional programming type stuff.

    And like that, the off-by-one mistakes disappear.

    • spauldo@lemmy.ml
      cake
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      foreach is useful when you don’t need to know the index of something. If you do, conventional i, j, k, etc. are useful.

      A lot of it depends what you’re doing (number crunching, for instance) or if you’re in a limited programming language (why won’t BASIC die already?) where parallel arrays are still a thing.