5 ms·
0 based arrays is objectively the preferred way for me and not for historical reasons. I write a lot of low level graphics algorithm stuff, and 1-based arrays w
by nadam 8y ago
0 based arrays is objectively the preferred way for me and not for historical reasons. I write a lot of low level graphics algorithm stuff, and 1-based arrays would complicate index arithmetic.
like now with everything 0 based having something like:
arr[offset1 * 32 + offset2]
would be the following if all my offsets would be 1-based and arrays would be 1-based:
arr[(offset1 -1) * 32 + offset2]
which is pretty arbitrary...
- syockit 8y agoYou could reshape it (https://docs.julialang.org/en/v1/base/arrays/#Base.reshape https://docs.julialang.org/en/v1/base/arrays/#Base.reshape). But if you're interfacing with libraries written with C interface you'd still have to subtract for both offset1 and offset2.
- baldfat 8y agoHistorically 0 based is for low level languages. 0 based makes sense for C. My issue is higher level languages Python, Java, C# there is plenty of things that just are complicated and doing arrays off 0 is one of them. Doing data science or statistics just makes it obvious that you have two different sets on numbers. 1 doesn't mean the same thing in every instance in your programming and the functional programming side of me hates that.
- b_tterc_p 8y ago“Objectively preferred for me” sounds an awful lot like it’s subjective
- oblio 8y agoA ton more people do high level programming, than low level programming. You guys build the tools and many more people use them.
- simondanisch 8y agothat may be your impression, because you dont know julia's powerful, no overhead indexing abstractions yet ;) i also write lots of graphics low level code, and i couldn't be more glad that i don't need to do those error ridden indexing calculations anymore, since they're simply not needed... note, that you can also seamlessly create new array types that store 0 indices into other arrays - and because of julia's great composability, i can make them work with my indexing agnostic algorithms while being 0 overhead compatible with opengl's memory layout :)