# Solving one based indexing

**URL:** <https://discourse.julialang.org/t/solving-one-based-indexing/96927>\
**Category:** Tooling\
**Created:** [April 1, 2023, 5:27am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927 "2023-04-01T05:27:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [April 1, 2023, 5:27am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/1 "2023-04-01T05:27:18Z")

</div>

When I introduce julia to new people, they are usually very excited. That is until they find out it uses one based indexing and conclude it is impossible to work with.  
The [OffsetArrays.jl](https://github.com/JuliaArrays/OffsetArrays.jl) package is an amazing effort to solve this problem. However, there are [lots](https://discourse.julialang.org/t/discussion-on-why-i-no-longer-recommend-julia-by-yuri-vishnevsky/81151) [of](https://discourse.julialang.org/t/does-abstractarray-itself-need-to-support-indexing-beyond-1-based/83324) [issues](https://discourse.julialang.org/t/offsetarrays-inbounds-and-confusion/81295) with this approach.

This morning, first of April, I realized that this is not a software or compiler problem. It is a hardware problem and hence needs a hardware fix. With that realization, the solution became very simple and elegant:

 ![keyboard](https://global.discourse-cdn.com/julialang/original/3X/f/5/f54c16c00c772d496cb6e3f78d01bfeddd44bbed.jpeg)

---

<div class="post-metadata">

**Author:** ![torrance](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torrance/32/38990_2.png) [@torrance](https://discourse.julialang.org/u/torrance)\
**Post date:** [April 1, 2023, 5:39am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/2 "2023-04-01T05:39:22Z")

</div>

And good riddance to off by one errors whilst we’re at it. Bravo.

---

<div class="post-metadata">

**Author:** ![KajWiik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kajwiik/32/199_2.png) [@KajWiik](https://discourse.julialang.org/u/KajWiik)\
**Post date:** [April 1, 2023, 8:11am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/3 "2023-04-01T08:11:37Z")

</div>

🤣

---

<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:** [April 1, 2023, 4:40pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/4 "2023-04-01T16:40:45Z")

</div>

I would like to report a bug. I’ve moved the key caps around on my keyboard to match your your pieces of paper in the image. This works perfectly until I have an array of size 10. When I try to access the 10th element which would be `A[9]` in Python, it renders as follows in Julia.

```julia
julia> A[0]
ERROR: BoundsError: attempt to access 10-element Vector{Float64} at index [0]
Stacktrace:

```

Please help. I’m using Julia to control the gears on my 10-speed bike, and a hill is coming up.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [April 1, 2023, 5:37pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/5 "2023-04-01T17:37:32Z")

</div>

You’ve probably already passed that hill (sorry for any inconvenience), but I think we could solve that by drawing inspiration from Python: just like they use `a[-1]` to mean the last element of of `a`, we could define `a[0]` to wrap the other way. Of course we’d have to limit all arrays to 10 or fewer items, but I think given the elegance of this hardware solution, it would absolutely be worth it. Care to submit a pull request?

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [April 1, 2023, 8:58pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/6 "2023-04-01T20:58:06Z")

</div>

> [@jw3126](#):
>
> This morning, first of April,

Please note that whereas it is first of April in Julia, in many other languages the same day is addressed as April zeroth

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [April 1, 2023, 9:01pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/7 "2023-04-01T21:01:55Z")

</div>

Unironically pointed out that the top of my thread does not make it clear that I reached a different position, so I moved the marked solution to my last comment, though my full thoughts are [here](https://discourse.julialang.org/t/is-offsetarrays-jl-a-poison-pill/85188/28).

- written April 0st 1913

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [April 2, 2023, 3:56am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/8 "2023-04-02T03:56:38Z")

</div>

While I appreciate the effort of the OP to solve this issue and the well-intentioned comments here, frankly this thread just solidifies my view that Julia cannot be trusted or recommended for serious work in The Real World ™. The correctness issues are simply too egregious. These issues arise from the Julia community’s casual—nay, reckless—and dismissive postmodernist attitude toward the notion of a singular _objective truth_ in how a collection should be indexed, and they cannot be solved until there is a dramatic shift in collective attitude.

I can only hope that, in the future, this problem is solved once and for all when Julia adopts [the correct indexing scheme](https://github.com/giordano/RandomBasedArrays.jl).

---

<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:** [April 2, 2023, 7:30am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/9 "2023-04-02T07:30:17Z")

</div>

> [@uniment](#):
>
> I can only hope that, in the future, this problem is solved once and for all when Julia adopts [the correct indexing scheme](https://github.com/giordano/RandomBasedArrays.jl).

Any person of culture would choose [the way](https://github.com/giordano/StarWarsArrays.jl).

---

<div class="post-metadata">

**Author:** ![Vidianos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vidianos/32/46647_2.png) [@Vidianos](https://discourse.julialang.org/u/Vidianos)\
**Post date:** [April 3, 2023, 5:40pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/10 "2023-04-03T17:40:14Z")

</div>

And then there is me, that whenever I see array numbering starting at one, I say, ok this is a good language. I know most programmers are used to 0-indexing, but I just find it more natural based on the usage of the English (and frankly most other) language.

When you say the first object of the array (which term I am pretty sure everyone uses) you should mean the object with index 1, not 0. If we meant 0, we would say the zeroth element of the array, but I haven’t heard anyone say that.

---

<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:** [April 3, 2023, 7:19pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/11 "2023-04-03T19:19:45Z")

</div>

🙂 Just in case anyone is taking this thread seriously, this is an April Fool’s joke. At least I think it is …🙂

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [April 3, 2023, 9:53pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/12 "2023-04-03T21:53:05Z")

</div>

![](https://global.discourse-cdn.com/julialang/original/3X/7/7/77f51728b2ee40f50990e5eaa30120a065fde590.gif)

---

<div class="post-metadata">

**Author:** ![oOosys](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ooosys/32/209566_2.png) [@oOosys](https://discourse.julialang.org/u/oOosys)\
**Post date:** [June 19, 2024, 1:07pm UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/13 "2024-06-19T13:07:12Z")

</div>

I have tested your hardware patch while getting the diagonals of an array … Somehow I was not able to get the main diagonal of a 4x6 array using it. I suppose I need another keyboard with the keys labeled: `[-3] [-2] [-1] [0] [1] [2] [3] [4] [5]` .

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [May 21, 2025, 5:17am UTC](https://discourse.julialang.org/t/solving-one-based-indexing/96927/14 "2025-05-21T05:17:11Z")

</div>

Haha yeah always choose the right tool for the right job.
