Yea I was mostly using python and made fun of matlab bc of its 1-index, the got addicted to it because scipy is so shit and it was much harder to implement while matlab was out of the box
Then I also got used to the 1-index as well. People in this sub are mostly SWE but scientific researchers code a lot too and julia aims for these people.
Julia should be more popular in the future bc it mogs Python, R, C++ in the science
Except that it really doesn't, even though people like to claim that it does for some reason. Math uses both 1- and 0-based indexing (with neither being significantly more common than the other); and also indexes using other ranges or even all sorts of non-numerical objects on the regular.
I find it more intuitive if the only thing I do with the index is use them... well, for indexing. But the moment you start needing to do some math on the index, I find 0-based better. In 1-based indexing I often find myself having to add and/or subtract one at some place and I more often get off-by-one errors
Regardless of which one you use the math can both be simpler or more complicated. Get the last element of the array in 1 index is just simply A[N] which in zero it's A[N-1]
Loops in 1 index are inclusive, loops in zero based don't contain the upper bounds.
But then things to do with various array math have a +1 in one indexed while zero usually don't.
It doesn't matter which system you pick. You're going to get some ugly +1 or -1 somewhere. It's just a question of where. You get used to both paradigms pretty quickly
If you want to index a matrix though, 0-indexing is more convenient since if the matrix is 0-indexed, for i in 0..<width*height, (i/width, i%width) indexes every element. If you use 1-indexed matrices, then you instead need i in 1..=width*height and (i/width, (i+width-1)%width + 1).
EDIT: Also, relativity can have index 0 be the + dimension and indices 1 to 3 be the − dimensions, which is kind of nice.
Yes, relativity goes nicely with the zero index convention imo. It's weird having spatial dimensions in index 2-4 instead of 1-3, and having time in index 4 is also not standard.
I actually just tried to be familiar but language-agnostic. The range syntax is based on Rust because I find it to be quite comfortable and intuitive, and it doesn't have the awkward issue of the range of possible meanings that : can have, but mine is more explicit in terms of right-openness or closedness, because I wanted to make it unambiguous what I meant for someone who isn't familiar with Rust range notation. Presumably that's also how Odin designed their range notation, assuming that's what you're referring to (I don't know Odin).
View all comments
45
u/SnooRegrets3590 Sep 18 '26
1-indexed is more intuitive for me when dealing with matrices and some advanced differential equations