Re:Again on 0-based vs. 1-based indexing
by codeflo on Wednesday January 20, 2021 @06:19AM
(#25845073)
You want a zero-slice because it’s a simpler base case in almost any even mildly complex algorithm. Without empty lists, you need many additional branches throughout a code base to handle the “no element” case, causing more potential bugs. There’s nothing “8-bit” about cleaner code, quite the opposite.
[ Parent
| on HN ]
Re:Again on 0-based vs. 1-based indexing
by yodelshady on Thursday January 21, 2021 @11:31AM
(#25860689)
No, you have no branches, because the "no element" case is *not a slice! It is a type error at generation!
Instead, I'm dealing with that case at literally every one of thousands of places where I might receive it*! That's not clean.
Re:Again on 0-based vs. 1-based indexing
by alentist on Sunday January 24, 2021 @03:07AM
(#25890286)
It is. Just like 0 is a natural number, the empty string is a string, the empty set is a set, etc.
If you've worked with mathematical proofs before, you'll have experience with how they make proofs shorter and more elegant.
That's why they're natural base cases.