• JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    13 days ago

    Arrays not starting at 1 bother me. I think the entrenched 0-based index is more important than any major push to use 1 instead, but if I could go back in time and change it I would.

    • Overshoot2648@lemm.ee
      link
      fedilink
      arrow-up
      0
      ·
      13 days ago

      It really doesn’t make sense to start at 1 as the value is really the distance from the start and would screw up other parts of indexing and counters.

      • Klear@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        13 days ago

        It doesn’t make sense that the fourth element is element number 3 either.

        Ultimately it’s just about you being used to it.

      • JackbyDev@programming.dev
        link
        fedilink
        English
        arrow-up
        0
        ·
        13 days ago

        Yeah, but if we went back and time and changed it then there wouldn’t be other stuff relying on it being 0-based.

        • Username@feddit.org
          link
          fedilink
          arrow-up
          0
          ·
          13 days ago

          It was not randomly decided. Even before arrays as a language concept existed, you would just store objects in continuous memory.

          To access you would do $addr+0, $addr+1 etc. The index had to be zero-based or you would simply waste the first address.

          Then in languages like C that just got a little bit of syntactic sugar where the ‘[]’ operator is a shorthand for that offset. An array is still just a memory address (i.e. a pointer).