5 ms·
I 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 prog
by henrikeh 6y ago
I 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?