5 ms·
The example using closed intervals makes sense. I see why you mention 1-based indexing, but it’s mostly a different beast. I’ll defend 1-based indexing here be
by tylerneylon 4y ago
The example using closed intervals makes sense.
I see why you mention 1-based indexing, but it’s mostly a different beast. I’ll defend 1-based indexing here because, having used Lua a lot, the indexing issue just goes away.
People like what they’re used to. Most coders are used to 0-based, but we all start life 1-indexed. We begin counts with 1: chapter 1, the 1st floor of a building (in the US), 1 AD, the 1st of Dec, etc.
In C/C++, 0-based makes sense because we often care about pointers and pointer arithmetic. But in languages without pointers, that reason goes away. And you can still use half-open intervals with 1-based indexing.
- _glass 4y agoI was born 0 years old.
- macleginn 4y agoWhich shows that you weren't born in Japan: people there are born 1 year old.
- programmer_dude 4y agoThey are not even though they start counting from 1. The child is still zero years old.
- mhink 4y agoIt's a matter of (natural language) terminology. It's the difference between asking "which year of your life are you currently in" as opposed to "how many full years have elapsed since you were born?"
- programmer_dude 4y agoAgreed. My previous reply just pointed out that 1 is not "how many full years have elapsed since you were born?". The answer to this question is still 0.
- deleted 4y ago[deleted]
- lupire 4y ago0-based is for offset arithmetic, not pointer arithmetic.
- GuB-42 4y ago> 1 AD And this makes things really confusing. 1999 is 20th century even if the year starts with "19". 2000 is still 20th century, 21th century starts in 2001. "BC" dates feel like negative numbers but they are not. Using closed intervals [10 BC, 10 AD] spans 20 years, but [10 AD, 20 AD] spans 21 years.
- rav 4y agoCan you explain what you mean by "having used Lua a lot, the indexing issue just goes away"? Most modern languages have facilities (iterator combinators) that make indexing less common than e.g. in C, but in my experience, you can never completely escape indexes, and for the indexes that I do have to deal with, I really want half-open intervals and 0-based indexing.