Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is obviously spaces vs tabs third rail in PL design, but riffing off of the language in the article, probably we should all agree on two opinions:

0-based indexing is inherently better for machines.

1-based indexing is inherently more natural for humans.

**

For a short stint I was running a (small) datacenter, and despite being an apologist for 1-indexed programming languages, I zero indexed EVERYTHING in the datacenter.

Let me just say, that was a huge mistake. Physical items are not offsets. Even though I was then working in a 0-indexed PL, The amount of contortion I had to do to remember zero indexing made the likelihood of errors higher (I did not make any that weren't quickly recoverable, but still).



> 1-based indexing is inherently more natural for humans.

Depends on what you are indexing. Time, for example, is very commonly represented as being 0-based by humans.


Sure, to the point where it's confusing when it's not (no year 0 e.g.)


My culture uses 0-based ages, where in your first year on earth you are 0 years old and turn 1 after you have been alive for an entire year, but I am not sure age would be any more confusing if it were 1-based. I don't see anything fundamental there. Other cultures do use 1-based ages (you are 1 on the day you are born) and they seem to get along just fine. Whatever you are accustomed to is what seems natural.


I have experience with 1-based indexes: basic/pascal. My 2nd language after basic was assembler. Off-by-1 bugs were plenty and confusing - mixing assembly with basic and pascal. Zero based with Java/Javascipt has felt a lot more natural than one based. Likely in 20y+ years there has not been an-off-by-1 bug. With that said: 0 based has felt totally fine and natural. All it takes to remember: inclusive/exclusive.




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

Search: