• juliebean@lemm.ee
    link
    fedilink
    arrow-up
    9
    ·
    1 year ago

    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
  • GodIsNull@feddit.de
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    1 year ago

    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.

    • Knusper@feddit.de
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      I’ve hardly ever looped over indices after college. For-each loops solve 99% of real-world problems in a better way.

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

    I always like to joke in coding interviews that I really like to make variable names as long as I can so they are very precisely named. Then when I get to a double nested loop I hit them with iterator and jiterator instead of I and j

  • youRFate@feddit.de
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 year ago

    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.