Can we still say that Julia's indexing is one-based?

I was looking at the Julia Developer Survey 2022 and noted that one-based indexing was a feature of the language that you could choose to like or dislike.

In the light of recent discussions here, here, and here and the general recommendation to avoid using the idiom

for i=1:length(v)

Can we still say that Julia’s indexing is one-based?

I would argue that most things in julia core/base are still using 1 based, so I’d call it one based.
Then there have been built some generic interfaces so that code can support general cases, and that is just nice so you dont have to specialize on everything. Makes it more composable.

1 Like

Julia’s Array is one-based. That doesn’t mean “Julia’s indexing” is one-based though, since indexing is clearly defined as the dispatch getindex and the available indices are defined in the interfaces as those returned by axes. Because of that, “is Julia one-based” is somewhat undefined: types can have an indexing Base but the language does not.

1 Like

Saying that Julia is one-based is problematic because it glosses over the fact the Julia also supports arbitrary-base indexing for AbstractArray.

I would say the default array type in Julia, Array is one-based.


its one based. its the everyday use that matters.


Array and Tuple have one-based indexing, but Julia itself supports any sort of indexing.

Excusing inaccuracies with claims to ‘everyday use’, whatever that is, is not a good idea.


Everyday use doesn’t 1-base because if you do that instead of using more generic iterators then GPUs and other array types aren’t supported. Most libraries are careful not to do this for a reason.

1 Like

To truly eliminate the influence of 1-based indexing outside of Array and Tuple, I propose Julia 2.0 should rename first(1:10) as beginning(1:10), and provide an offset option for users who prefer zeroth(1:10) or second(1:10), all of which should evaluate to 1. :grinning:

This is basically a legacy discussion at this point, held over from an ancient time. As already highlighted, you can index however you want and the best practice is to dispatch for different index schemes.