Hacker News new | past | comments | ask | show | jobs | submit login

I write in primarily in 3 languages, 2 start indexes at 0 and the third starts at 1.

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.




If you ever have to pack multidimentional data in a flat array, I wish you luck, then. In this case, starting at 1 messes up lookup and insertion. You have to insert "-1" or "+1" pretty often. Too hard to get right in my opinion, I prefer the easier way: to start at 0.


Shouldn't the "index start value" just be a compilation directive?


I am doubtful about the value of reason 2. "Intuitive", very often, just means "familiar", and I think that's the case here. It's not too difficult to get used to starting at 0, at which point there's no loss in "intuitiveness" from doing so.

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 couldn't bring myself to stick null pointers here and there for the convenience of syntax :P

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.


For 98% of all software, 'elegance of maintenance' is vastly more important than your #1. Most software doesn't need the absolute fastest hand tuned implementation, it needs an implementation that the poor schlub who inherits it in 15 years can understand.

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.


I'm a actionscript developer at my day job and I would totally take up this approach if I didn't have to deal with screen/stage coordinates all the time.

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"!




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: