|
|
|
|
|
by crowselect
472 days ago
|
|
Meanwhile off-by-one errors are ludicrously common… People can learn to deal with adding 1, but it’s still a cognitive encumbrance that loads us down and makes life harder. Not that I’m advocating for one-based indexing. At this point consistency is more important than whatever the easier solution is. |
|
Off by one errors in general have nothing to do with being 1 or 0-based indexed.
In French off-by-one error is called “the post and fence problem” because there's always one more post than piece of fence (unless your fence makes a loop).
It arises because it's easy to confuse the number of intervals between elements and the number of elements (which is also: do I need to include the bounds or not). 1-based indexing isn't going to help at all in the general case (it will help for the most basic error which is getting the last element of an array with `a[a.length]`, but that's it)