by edw519 · 17y ago · 0 comments
Not withstanding Dijkstra's logical arguments, I have adopted starting at 1 for 2 reasons:
1. I don't have to think about "shifting" data in order to look at it in the third language.
2. I don't have to "think" at all. It's intuitive that the first element is "1".
I just insert a null in the first position of any array in a 0-starting language.
Reason 1 has more force. I don't run into it very often when transferring data from one language to another -- I don't do very much of that -- but I do when, e.g., translating between code and standard mathematical notation.
i see a lot about code being written for humans, but i'm not onboard with it. elegance in how it executes is #1, and elegance of maintenance is #2.
Now I'm not agreeing about the particular indexing argument put forth by edw519, I think zero indexes lead to cleaner code whenever you have to do math with them, but unless you can make an honest case for maximum performance, I have to disagree with your assertion about elegance.
You see, the backend of our project is in Coldfusion which has 1 based indexes for Array's and it has led to head-butting screen confusion when requesting the current index from the server. Then the visual side is always 1 based when showing data to the end-user, I'm always thinking I'm the problem in the middle.
There have been numerous occasions where QA have called me to ask why the first slide in a slideshow is called "Slide 0"!