So if your answer started with “because in C…”, you’ve been repeating a good story you heard one time, without ever asking yourself if it’s true.
Mike Hoye digs into the history of zero-indexed arrays in Citation Needed. Fantastic walk through the history of computing, and a fun reminder of how comfortable it is to leave our beliefs unexamined.
November 1, 2013 at 10:52 pm
I have to say… I don’t really get his point. Sure, all the history of computing decisions have tradeoffs and lots of details about How Things Work are purely arbitrary. It’s interesting to know the real history, and sure sometimes the explanations get munged a bit in translation. But his entire premise is a little shaky. “It’s not pointer arithmetic, stupid!” But then in the end, yes it is, just at compile time instead of runtime? Color me unimpressed by this “debunking”.
Zero-indexed arrays in C make perfect sense if you understand how the language is handling memory behind the scenes. But regardless of why C works that way, the fact is that C is the most influential and important computer language in history, and the vast majority of popular languages these days picked up their basic structure from C, so the zero-index remains. So yes, the answer is “We use zero-index because in C, that’s how it worked”.
As for the Von Neumann architecture and the rest of the ranting, sure one can imagine other ways to structure a computer, but most people thankfully spend their time doing real things with the computers we have instead of trying to start from scratch over and over again. Questioning your assumptions is a good thing, but Real Artists Ship.
November 3, 2013 at 1:18 am
I just posted a comment to the effect that JOVIAL (circa 1961) had zero-indexed arrays at least 5 years before BCPL emerged, as shown by a JOVIAL specification available in the ACM Digital Library. And, my guess is that JOVIAL wasn’t the first. Unfortunately, “real” history is dependent on who is doing the remembering and recording. And, I have to say, Mike Hoye seems to get a bit testy with those who question his recorded history…