• lefixxx@lemmy.world
    link
    fedilink
    arrow-up
    5
    arrow-down
    11
    ·
    1 day ago

    How is arrays starting at 1 still a controversial take. Arrays should start at 1 and offsets at 0.

      • Something Burger 🍔
        link
        fedilink
        arrow-up
        1
        ·
        11 hours ago

        Not in languages where you don’t manually handle memory, such as PHP, SQL, Python… Higher-level languages using 0-indexed arrays are letting the abstraction leak.

    • Traister101@lemmy.today
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      1 day ago

      So what’s 0 do then? I’m okay with wacky indexes (I’ve used something with negative indexes for a end-index shorthand) but 0 has to mean something that’s actually useful. Using the index as the offset into the array seems to be the most useful way to index them.

      • labsin@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        4 hours ago

        I’d say the index is actually an offset is a reasoning for explaining why it should start at 1. If index was an index, I’d just start at 1.

        I don’t think any one is better than the other, but history chose 0.

        That you can choose it in VB is probably the worst option :D