3 ms·
Right, 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 t
by edtechdev 15y ago
Right, 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...