• dan@upvote.au
      link
      fedilink
      arrow-up
      0
      ·
      2 months ago

      Visual Basic used to let you choose if you wanted to start arrays at 0 or 1. It was an app-wide setting, so that was fun.

      • UndercoverUlrikHD@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        2 months ago

        Writing Lua code that also interacts with C code that uses 0 indexing is an awful experience. Annoys me to this day even though haven’t used it for 2 years

            • Sonotsugipaa@lemmy.dbzer0.com
              link
              fedilink
              English
              arrow-up
              0
              ·
              2 months ago

              Lua - Portuguese feminine noun for “moon”, coming from the Latin “luna”
              Luna - Latin, feminine noun (coincidentally identical to the Italian noun, also feminine)

              Yup, Lua is a girl.

        • pelya@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          2 months ago

          In Lua all arrays are just dictionaries with integer keys, a[0] will work just fine. It’s just that all built-in functions will expect arrays that start with index 1.

          • my_hat_stinks@programming.dev
            link
            fedilink
            arrow-up
            0
            ·
            2 months ago

            That’s slightly misleading, I think. There are no arrays in Lua, every Lua data structure is a table (sometimes pretending to be something else) and you can have anything as a key as long as it’s not nil. There’s also no integers, Lua only has a single number type which is floating point. This is perfectly valid:

            local tbl = {}
            local f = function() error(":(") end
            
            tbl[tbl] = tbl
            tbl[f] = tbl
            tbl["tbl"] = tbl
            
            print(tbl)
            -- table: 0x557a907f0f40
            print(tbl[tbl], tbl[f], tbl["tbl"])
            -- table: 0x557a907f0f40	table: 0x557a907f0f40	table: 0x557a907f0f40
            
            for key,value in pairs(tbl) do
              print(key, "=", value)
            end
            -- tbl	=	table: 0x557a907f0f40
            -- function: 0x557a907edff0	=	table: 0x557a907f0f40
            -- table: 0x557a907f0f40	=	table: 0x557a907f0f40
            
            print(type(1), type(-0.5), type(math.pi), type(math.maxinteger))
            -- number	number	number	number
            
    • lefixxx@lemmy.world
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      2 months ago

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