Hacker News new | ask | show | jobs
by jebej 2872 days ago
You can use whatever start index you like: https://docs.julialang.org/en/stable/devdocs/offset-arrays/#...

For a pre-baked solution: https://github.com/JuliaArrays/OffsetArrays.jl

1 comments

The problem is the default behaviour: in Ada you can use whatever you want, in Julia the default is 1-based which is quite controversial.
Picking whatever you want is one line of code, and similar to the line you'd need to allocate any array. And your choice propagates to the downstream operations.

Instead of complaining in the abstract, check it out, you'll be impressed. https://julialang.org/blog/2017/04/offset-arrays

I already know about this but if you use someone else's code in a library for example in Julia the library will most likely only work with 1-indexed array, in Ada it will work with any base index.

Default matters!

It's straightforward to write library code in Julia that handles any type of index. If it doesn't, it is probably old code from before the time before offset arrays. Take a look at Tim's linked blog post.
It is straightforward to create a language where a user can specify any type of index (like Ada), if you need to import a library everywhere to have the correct behaviour then this library should be a part of the language instead.
The controversy reminds me a bit of the "Python uses whitespace semantically, oh my" back in the days. Close to bikeshedding: Lots of discussion about a very minor point that everyone has an opinion on though.

(not referring specifically to you here!)