3 ms·
One counterargument is that in natural language, we tend to talk about numbers 2 to 12 and not the interval 2 <= x < 13. The argument for the latter versus the
by simonster 13y ago
One counterargument is that in natural language, we tend to talk about numbers 2 to 12 and not the interval 2 <= x < 13. The argument for the latter versus the former is probably Dijkstra's weakest: the claim is merely that this makes the empty range "unnatural." The former convention implies one-based indexing for the same reason that the the latter implies zero-based indexing.
In Julia, the natural numbers 2, 3, ..., 12 are expressed as 2:12 and the empty range starting at 2 is expressed as 2:1.
- tristanz 13y agoThis is also typically written in algorithms like: N = rows(data) for i in 1:N blah So even though 1:0 may seem not unnatural, it actually reads perfectly in most code.
- Fomite 13y agoFor me, the biggest positive is avoiding indexing errors between 0-indexed languages (Python) and 1-indexed data (almost everything I get). Patient IDs, simulation code, etc. hardly ever starts with "0" as the first ID unless it's been created by a computer scientist, and having to make sure everything is looking at ID-1 instead of ID is a pain. And makes code less useful to people who use the code instead of making it.