Solving one based indexing

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 package is an amazing effort to solve this problem. However, there are lots of issues 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:

55 Likes

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

4 Likes

:rofl:

4 Likes

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

19 Likes

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?

11 Likes

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

28 Likes

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.

  • written April 0st 1913
1 Like

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 :tm:. 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.

10 Likes

Any person of culture would choose the way.

8 Likes

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.

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

3 Likes

3 Likes

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