3 ms·
I suspect the real reason has more to do with the pragmatics of machine code. It's extremely common to want to refer to some dynamic offset of a fixed location
by goodside 15y ago
I suspect the real reason has more to do with the pragmatics of machine code.
It's extremely common to want to refer to some dynamic offset of a fixed location in memory, like if you have an array of equal-length items stored consecutively. If you have two literal addresses called Start and Index, you'd like to be able to say something like "Start[Index]" and have it mean "Read from Index, and whatever number is there, move that many spaces forward from Start, and give me that". It's handy that if Index is a cleared region of memory, you can say "Start[Index]" and have it mean the same thing as just "Start". More importantly, if "Start[Index]" only meant "Start" when Index was 1, that would imply that if Index were 0 that Start[Index] would refer to the spot right before Start, which is not only useless but outright dangerous.
- edtechdev 15y agoRight, it makes sense when dealing with machine code and when making the compiler do extra work for you (converting one-based to zero-based indexing) would be too much work for the compiler implementer or is too slow (like on machines back in the 70s and 80s) or it would abstract too far from what is happening underneath the hood, possibly leading to errors. But like many features of programming languages and operating systems (case-sensitivity, global menu bar, python's colon...), zero-based indexing is something that made perfect sense in the context and time in which it was originally designed and implemented, but it's really no longer necessary in most cases today, and only survives because of tradition and blind cargo cult-like copying of what others did before.
- goodside 15y agoYou're vastly oversimplifying. In physics and finance, the "initial time" has always been t_0, not t_1. This has absolutely nothing to do with machine code, or with "blind cargo-cult copying". There are intrinsic reasons for doing it this way, which I'll leave for you to ponder yourself, ideally in a quiet room in a lotus position. Traditions are not always arbitrary. Don't dismiss them until you're damned sure why they've survived, especially when you know for a fact that quantitative fields filled with high-order geniuses haven't bothered to scrap them. "Cargo-cult" thinking is a pernicious influence, but it's exceptionally rare that it's the complete explanation of anything.
- edtechdev 15y agoI'm addressing the topic of the post: the use of indexes in programming, not names used for variables that store an initial time. myarray[2] doesn't mean 'myarray at time 2'
- mjw 15y agoOne advantage I think the parent is alluding to, is that zero-based indexing makes it a bit easier and more natural to generalise between continuous (functions on R) and discontinuous (functions on N) situations. Since the latter are often used to approximate the former, this is quite handy.
- burgerbrain 15y agoCare to explain why Dijkstra arguments for zero-indexing hold any less true today than in 1982? His arguments make a great deal of sense to me so I take exception to the assertion of cargo cultism.
- jmesserly 15y agoPython's colon-before-indented-block resulted from usability tests of people learning how to program. I don't see why that would have different results today. See page 7 of this presentation: http://mvdirona.com/jrh/TalksAndPapers/GuidoVanRossum_21_years_of_python.pdf http://mvdirona.com/jrh/TalksAndPapers/GuidoVanRossum_21_yea...