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

**URL:** <https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009>\
**Category:** General Usage\
**Created:** [July 10, 2022, 5:19am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009 "2022-07-10T05:19:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterkovesi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peterkovesi/32/5946_2.png) [@peterkovesi](https://discourse.julialang.org/u/peterkovesi)\
**Post date:** [July 10, 2022, 5:19am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/1 "2022-07-10T05:19:11Z")

</div>

I was looking at the [Julia Developer Survey 2022](https://form.jotform.com/221651728025452) 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](https://discourse.julialang.org/t/discussion-on-why-i-no-longer-recommend-julia-by-yuri-vishnevsky/81151), [here](https://discourse.julialang.org/t/does-abstractarray-itself-need-to-support-indexing-beyond-1-based/83324), and [here](https://discourse.julialang.org/t/offsetarrays-inbounds-and-confusion/81295) 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?

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [July 10, 2022, 5:45am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/2 "2022-07-10T05:45:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 10, 2022, 5:58am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/3 "2022-07-10T05:58:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 10, 2022, 7:15am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/4 "2022-07-10T07:15:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kodintent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kodintent/32/32225_2.png) [@kodintent](https://discourse.julialang.org/u/kodintent)\
**Post date:** [July 10, 2022, 7:21am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/5 "2022-07-10T07:21:52Z")

</div>

its one based. its the everyday use that matters.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [July 10, 2022, 7:41am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/6 "2022-07-10T07:41:36Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 10, 2022, 9:38am UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/7 "2022-07-10T09:38:46Z")

</div>

> [@kodintent](#):
>
> its one based. its the everyday use that matters.

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.

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [July 10, 2022, 12:29pm UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/8 "2022-07-10T12:29:56Z")

</div>

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`. 😀

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [July 10, 2022, 12:58pm UTC](https://discourse.julialang.org/t/can-we-still-say-that-julias-indexing-is-one-based/84009/9 "2022-07-10T12:58:17Z")

</div>

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.
