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

Yes. It looks wrong and feels wrong. I can adjust to indentation styles, programming styles, etc. but 1-based indexing is an absolute deal-breaker for me. 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.



> 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?


The scientific programming community, starting with Fortran, has, on the contrary, settled on 1, because it is mathematically the most natural start.


And yet, the set of natural numbers in mathematics is most often taken to start at 1. Mathematicians don’t have a problem with indexing.


In Sweden, the set usually referred to as "de naturliga talen" (the natural numbers) is any number n such that 0 <= n.

Or, at least, that was the case when I did maths there. No idea what the default interpretation is these days.

This is mostly why I don't say "natural numbers" and instead say "positive integers" or "non-negative integers", depending on if I want 0 included or not.


Is it? Most nat's are built from zero and succ(n) in my experience.


(I'm a mathematician)

Honestly, not that many people in math think about the construction of the natural numbers frequently. Yeah, we learn about it of course, but that's about it. Very often the natural numbers do not include 0. Often they do. I've seen $\mathbb Z_{\geq0}$ and $\mathbb Z_+$ used to avoid having to worry about it.

Hell, different countries can't even agree on whether 0 is positive. In France, 0 is considered both positive and negative. In USA, 0 is considered neither.

(quick edit: I realize my last paragraph makes the $\mathbb Z_+$ option seem weird. I do math in the States.)


That's what Wolfram Mathworld suggests: specifying a subset of the integers. :-)


Only if you need zero, which you don't need for indexing. Peano's original axioms started from 1 (which is logically equivalent to starting from 0, or -1, or potato) if all you are doing is counting)


Database auto-indexed columns have entered the chat.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: