4 ms·
say you have an array of memory items. [][][][][][] this will be marked with some marker (your varible names contain this offset into memory.. logical. thats ho
by vectorEQ 8y ago
say you have an array of memory items. [][][][][][]
this will be marked with some marker (your varible names contain this offset into memory.. logical. thats how computer works.)
then in computer, (assembly) you will request an element by saying for example base_offset+(1elem_len). that would make it logical to use 0 as an offset, because then you can use 'nelem_len' as a generic number to incrememnt the offset by to select array elements.
thus for a computer and how it functions, 0-based array would make more sense, and any other thing, would just be some overlay over how a computer works just to make it more human readable....
computers dont care for what is first idex, it will always equate to base+n*elem_len to have to find the actual location in memory...
if people have been discussing that for decades and what is better, it's just another example of people not understanding what is an opinion,and what is objectivley true... none is better, your compiler is taking care of business, really it is, and no longer like it was 1999... they have been patched many times!
- mikec3010 8y ago> for a computer and how it functions And what about for a human and how it functions? Are humans here to make computers' lives easier or vice versa? Humans think from 1...N inclusive and this is the source of a litany of bugs when users first learn a language. And what you described in asm is just one implementation. In fact, the array documentation says Julia doesn't guarantee tight packing so it doesn't even apply. The next element could be anywhere, and in fact wont be in the case of heterogeneous arrays. Asm is also not straightforward. For instance zeroing a register isn't done with the mov instruction but xor
- celrod 8y agoI think vectorEQ's point was actually that 1-based indexes are a reasonable abstraction. "computers dont care for what is first idex...none is better, your compiler is taking care of business"
- ur-whale 8y ago>Humans think from 1...N I think you're assuming everyone thinks the way you do. I assure you that's not the case. There are legions of people (and not just programmers, math folks do it too) who don't "think from 1 to N"
- mikec3010 8y agoTrue, after they learn a programming language. I meant when we're children and taught to count, we don't start at 0.
- ur-whale 8y agoAgain assuming: that may be true in the place where you were educated.
- mikec3010 8y agoYou're assuming I'm wrong. Show me where kids are taught to count starting at zero.
- celrod 8y ago"taught to count" I think that is the key. "1, 2, 3. There are 3 apples." is a little easier than "0, 1, 2. There are 3 apples." Counting the first item as "1" total items leads to 1 being more natural in the same way that incrementing a pointer by 0 giving you the first element is more natural. The former is the abstraction layer most people are more familiar with.
- orhmeh09 8y agoIf you look at ranks for worldwide sporting events , you’ll note that approximately none of them indicates first (zeroth ?) place with a 0. Can you give an example of a place where education at early childhood level is carried out as you claim ?
- 8y ago
- simonbyrne 8y agoIt turns out that compilers are pretty good at eliding constant integer offsets.