• SorryQuick@lemmy.ca
    link
    fedilink
    arrow-up
    2
    ·
    2 hours ago

    Says who?

    By definition, an index is

    a number or symbol or expression (such as an exponent) associated with another to indicate a mathematical operation to be performed or to indicate use or position in an arrangement

    Since the arrays offsets alao tell us about the items’s position in the array, is it not then an index?

    People take these terms way too seriously. Hell, many languages have their “list” implemented as an array. What then do you call the index/offset?

    • lime!@feddit.nu
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      2 hours ago

      if you want my opinion (<- see now you can’t tell me i’m wrong, it’s an opinion) then the difference is that an array is by definition a memory address that’s designated as the beginning of an array, and it’s got an offset because the first element is at that specific address and further items are offset from that address. so you add the offset to the address to get the nth item. a list, meanwhile, can be basically any implementation under the hood, but it’s commonly a linked list. the way you get the nth index there is you count up from the first position. since the implementation is opaque and may be spread out in memory you can’t arithmetic your way to an index, you need to follow the pointers.

      java’s arraylist is a list backed by an array. java’s vector is a list backed by a linked list.

      • SorryQuick@lemmy.ca
        link
        fedilink
        arrow-up
        1
        ·
        1 hour ago

        That doesn’t really address what you call it. Names only really just exist to get your point across. Inexperienced devs may not know what an offset means (or why we use that), so index does the job. An experience dev knows how it works anyway, so whether you say index or offset won’t matter. By virtue of the common denominator, I simply use index everywhere.