2 ms·
This syntax is available in julia as well, but I'm not sure it's a great idea to encourage mixing the two indexing behaviors, even if they have different syntax
by KenoFischer 10y ago
This syntax is available in julia as well, but I'm not sure it's a great idea to encourage mixing the two indexing behaviors, even if they have different syntax. As I hinted
in the original reply, I have seen very few cases where the
choice of index offset actually makes a difference. For
example, loops over indices generally use `eachindex` which doesn't care about your choice of index base.
- rch 10y agoThat's interesting - thanks. I don't think anyone is eager to mix indexing behaviors either.
- KenoFischer 10y agoI just realized that when I said, "this syntax is available", people might have understood it to mean, "you can use this syntax to index arrays" (which is not true for the array type defined in base). What I meant was, "you can define an array type with this indexing behavior without changing the language (since you can override the behavior of both () and [] on a particular type)".
- ScottPJones 10y agoActually, for the sort of low-level bit twiddling code that I frequently do, 1-based indexing complicates the code greatly. I also need to pass structures that contain indices back and forth to C, so the 1-based indices cause extra overhead to constantly add or subtract the size of the element. I find that it's the largest cause of bugs in my code (which is why I really want Gallium working!)