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

> It's one of the few things the programming community has settled on - indexing starts at 0, as it is mathematically the most natural start.

When you're in the supermarket and you're counting how many items are in your shopping cart, do you start from 0?



It depends on what you think you're doing.

If you are counting, 1-based makes a lot of sense. If you're indexing, they're equally valid approaches. However, if you're indexing then you should be able to use an arbitrary range and not be restricted to one or the other (with a mapping function from your actual range to the language's base).


> When you're in the supermarket and you're counting how many items are in your shopping cart, do you start from 0

Yes, because the cart starts empty. But, more to the point, I don't call the thing I put into the cart that causes it not to be empty the zeroth item.


You start with an empty cart, right?




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: