4 ms·
Can't reply anymore to flagged-to-death sibling, but wrt "1-based array indexing": I've actually found behaviour of "zero-avoidance" a good battle-tested heuri
by synthmeat 8y ago
Can't reply anymore to flagged-to-death sibling, but wrt "1-based array indexing":
I've actually found behaviour of "zero-avoidance" a good battle-tested heuristics to coding. A lot of numeric spaces can be mapped as to be >0 or >0<. Obviously (?) not all of them can, but it's helpful in reducing cyclomatic complexity in logic code, as well as to consumers so they can uniformly handle all falsey values.
Arithmetic is much safer without 0.
- mathdog 8y agocyclomatic complexity in logic
- vectorEQ 8y agooffset 1 is logical if you look at the machine code / data in memory. if you have array [a,b,c,d] array[0] is a which in computer is logical. why? because it stored in memory 'abcd' (forgetting endianness for sake of argument...) and the offset from the base pointer to a is 0. so it makes perfect sense for arrays to start at 0, as there is no offset from the base... there is not 1 item offset from the base :s if you find it confusing i would say learn how computers actually operate instead of arguing from some theoretical frame of mind which has nothing to do with how computers work. a computer isn't mathematics or some arithmetic machine. just because arithmetic is safer without 0 doesn't mean it's logical for a computer to suddenly have different array indexing. array indexing on a computer has nothing to do with maths. just memory layout and pointers... #addsfueltofire
- Tarq0n 8y agoOk, but why should that influence a managed language with no pointers?
- giornogiovanna 8y agoIt shouldn't. One-based indexing is what all the research uses, so it is undeniably the better choice for Julia. But zero-based indexing isn't just a memory trick, it makes lots of math easier when you're concatenating ranges or slicing arrays or doing modular arithmetic anywhere near an array.
- goto11 8y agoGOTO is logical when you look at machine code - that does not mean it is the best possible abstraction. There is a reason we use higher level languages.