4 ms·
offset 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 s
by vectorEQ 8y ago
offset 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.