News for hackers. Stuff that matters.
Re:Lua, a Misunderstood Language (2021) by karmakaze on Thursday September 29, 2022 @01:24PM (#33024100)
I'll trust math more than human language evolution as a solid basis for indexing.

Also Julia's (default) 1-based indexing has become a mess.

Re:Lua, a Misunderstood Language (2021) by nequo on Thursday September 29, 2022 @01:58PM (#33024673)
0-based indexing is not universal in math either. We often index time from 0, but when we refer to components of a vector, we often index those from 1. For example, I'd write or see things like $\sum_{k=1}^N f(x_k)$ where $x$ is a vector. In these cases, 0-based indexing would look out of place.
Re:Lua, a Misunderstood Language (2021) by jhbadger on Thursday September 29, 2022 @02:08PM (#33024815)
Pretty much all programming languages designed for math are 1-based. Besides Julia, there's R, Mathematica (or "Wolfram language" as it is called these days), and Matlab.
Re:Lua, a Misunderstood Language (2021) by systems on Thursday September 29, 2022 @03:15PM (#33025657)
I am curious, what mess did 1-based indexing create for Julia ???
Re:Lua, a Misunderstood Language (2021) by Jtsummers on Thursday September 29, 2022 @03:21PM (#33025753)
My understanding (outside the community, I use it but am not hugely familiar with it) is that the 1-based indexing is the default, but you can select any range. Routines that assume 1-based indexing then break on anything that, well, isn't 1-based.

See: https://docs.julialang.org/en/v1/devdocs/offset-arrays/

Discusses how to generalize the code so it handles arbitrary ranges.

Re:Lua, a Misunderstood Language (2021) by ModernMech on Thursday September 29, 2022 @06:24PM (#33028141)
IMO 1 based and 0 based is a wash as to which is better, but the only definitive wrong answer is an arbitrary base. It may seem like a good compromise (just use whichever you prefer!), but it opens the door to a mars climate orbiter disaster waiting to happen.
Re:Lua, a Misunderstood Language (2021) by Jtsummers on Thursday September 29, 2022 @07:35PM (#33028814)
Arbitrary indexing is fine as long as people are sane about how they do things and don't assume. In almost every language these days you can use this or something analogous:

  for x in some_collection
Which is great if you don't need the index, and if you do need the index then you want the equivalent of:

  for i in some_collection.range
or

  for i, x in some_collection.enumerated
Being forced to use 0-based or 1-based or even strictly integer-based indexing is the wrong thing. If you want to use characters/runes as your index you should be able to. If you want to use some enumerated type, you should be able to. And if you want some subrange of one of those, you should be able to.
Re:Lua, a Misunderstood Language (2021) by ModernMech on Friday September 30, 2022 @09:25AM (#33034529)
> as long as people are sane about how they do things and don't assume.

Ime this expectation of developers doesn’t scale reliably. We can’t even trust engineers to keep feet and meters straight. Relying on conventions for correctness is a recipe for disaster.