Hacker News new | ask | show | jobs
by oneweekwonder 2980 days ago
> A bunch of wrongs don't make a right :-)

Funny how I always thought zero-based numbering[0] was a hack. Just in computer science a hack will become the right way? Any other fields where hacks became the new norm due to technical restrictions?

Your statement is a opinion.

To add to the list of languages using arrays in a "gross" way: pgsql, pascal, lua.

[1]: https://en.wikipedia.org/wiki/Zero-based_numbering#Origin

3 comments

The way I've thought about this is that it's about whether an index is the name or the offset of an element of an array. Indices have a torsor-like structure, where you can subtract indices i and j to get an offset j-i from index i, and there is the relationship a[j] == a[i + (j-i)]. Zero-indexing is the special case that the name is the offset from the first element.

Because of this, I figure any language that supports 1-indexing should also support arbitrary ranges for the indexing, like in Ada. (Basically, what's so special about 1?)

I always thought it neatly mimicked the way we think of age. When you are born you start at 0. You only turn 1 after you have lived a year.
That's an argument for starting at 1, not at 0.

At age 0, you have no elements in your array of years. So the first year is also element 1.

If you want code to reflect the way you've done counting and arithmetic your whole life, you'd want it to start at 1.

That would be defining it as a time span and using the time since start as index.

Which to me is one step away from using the timepoint as the index iteself (zero as start), verus (1 year from zero).

How would you index the time before the first birthday?

Insofar as a timespan is the same as counting years, then yes. If elements in the array are years, then the time before your first birthday doesn't appear.
> Your statement is a [sic] opinion.

Yeah, that's why put a smiley there. :-)