3 ms·
Julia also has 1-based indexing .. You get used to it pretty quickly.
by sriku 6y ago
Julia also has 1-based indexing .. You get used to it pretty quickly.
- markrages 6y agoYes, you just crap up your code by subtracting 1 anywhere you need to calculate an index. I moved from Matlab to Python and the biggest improvement was zero-based indexes.
- pjmlp 6y agoJust like you do with the upper index in zero-based languages , as length > max index. Apparently this little detail is never taken into account.
- Reelin 6y ago> You get used to it pretty quickly. You don't if you're writing low level algorithms. It's difficult for me to articulate the exact problem but I liked 1-based indexing until I needed to implement some algorithms that operated on multi-dimensional arrays element wise. Things just don't compose the right way. It's actually the primary reason I don't make more use of Julia. I like the syntax and overall design more than Python but it just isn't worth it to me. (If you're wondering what I'm doing in an Lua comments section, it's because I really like the ideas behind some of the Lua based languages such as Terra.)
- henrikeh 6y agoI primarily work in 1-indexed languages, but I think everyone is missing the forest from the trees in this discussion: indexing should be selectable by the programmer. One or zero indexing is a question about domain and communication. In signal processing, it is quite normal to need a negative index (autocorrelations f.x.). Ada (and I believe Pascal and Julia) has supported for specifying the indexing type, which can then be selected to match the problem domain.
- google234123 6y agoOh god, not more inconsistency! That sounds horrible
- henrikeh 6y agoIt really isn’t. It’s just a way of communicating the problem domain in the language. Maybe you should try it before passing judgement.
- ygra 6y agoVisual Basic’s Option Base comes to mind. And Pascal had very nice facilities for arbitrary array bases. I think you could define an array with indices from 18 to 22 is you liked, which can definitely simplify code doing the indexing.
- freemint 6y agoI don't get that 1 based indexing debate in regard to LUA and Julia. Both came up recently on hackernews. In LUA you can use the metatable functionality to implement 0 based indexes. In Julia you can overload the array access operation too. There a packages which allow zero based indexing. Or even StarWars based indexing including the machete viewing order. https://github.com/giordano/StarWarsArrays.jl https://github.com/giordano/StarWarsArrays.jl Julia's array interface has has functionality what the first/last index is, so you can use it in other peoples code. If they haer coded 1 as first index just make a pull request to fix it.
- pansa2 6y ago> In LUA you can use the metatable functionality to implement 0 based indexes. I tried to do that a while back and kept coming across corner cases that didn’t work. Is there a complete implementation of zero-based arrays for Lua available anywhere?