4 ms·
Off by 1-errors is not part of the original quote, but is just a later addon to make it funny. They also tend not to be very hard.
by yxhuvud 1y ago
Off by 1-errors is not part of the original quote, but is just a later addon to make it funny.
They also tend not to be very hard.
- TeMPOraL 1y agoExcept when they're part of some base assumptions in the domain or dozen of layers of abstractions below you. They are hard to prevent from happening.
- tombert 1y agoThey're not hard but I will say that when I was writing an app that was using both JavaScript and Julia, I kept getting off-by-one errors because Julia starts at 1 instead of 0. Really the only time in my entire professional career that off-by-one errors have actually given me headaches.
- bobthepanda 1y agoI think that is from a time when popular programming languages varied in their behavior and also when people were writing for loops with incrementation all the time. A lot of languages have just settled on zero indexing, and many now have some variation of for/each or for/of that would eliminate a lot of potential ways to encounter this error.
- tombert 1y agoYeah, I mostly will do map/reduce/filter when possible, and obviously in those cases indexes don’t matter. It could start at index 12345 for all I care with that stuff. Occasionally, though, I need to use the same index across multiple items, there’s not a trivial means in which to zip, and at that point I have to use an old school for loop. That’s when the 1-index vs 0-index bites me.