9 ms·
> array[i] will check to make sure that array has at least i elements. At least i+1 elements, right? Or am I getting caught up by one of the three hardest prob
by baseballdork 6y ago
> array[i] will check to make sure that array has at least i elements.
At least i+1 elements, right? Or am I getting caught up by one of the three hardest problems again?
- steveklabnik 6y agoNope, you're right, it was me that got caught up by it. :) Thanks, I'll fix that now. https://github.com/rust-lang/blog.rust-lang.org/commit/fe2414d86d55e0f6d259a7eb97bb1b4d6026ce5f https://github.com/rust-lang/blog.rust-lang.org/commit/fe241... (should roll out in a few minutes)
- staticassertion 6y agoAnd this is why we need bounds checking.
- kbenson 6y agoThe thing that keeps the "two hardest things in CS" joke alive and still funny is that it's so, so true.
- dagmx 6y agoEdit: brain not woken up yet. It’s because of zero indexing. ———- Original question: Out of curiosity, why the +1?
- Sosh101 6y agoZero indexing probably
- dagmx 6y agoMakes sense. My brains clearly not woken up yet because I thought the `i` check accounted for the zero indexing.
- tryptophan 6y agoArrays start at 0. example_array[5] is actually the 6th number in the array.
- dagmx 6y agoAh yeah that makes sense. I was thinking the `i` check already accounted for the zero indexing.
- Tade0 6y agoIIRC there were two problems that were the hardest: 1. Naming things. 2. Cache invalidation. 3. Off by one errors. Number 3 apparently the hardest one.