4 ms·
> Also, my single biggest all time source of off by one errors is translating between mathematical notation and code in a 0-based language. If you were working
by xscott 6y ago
> Also, my single biggest all time source of off by one errors is translating between mathematical notation and code in a 0-based language.
If you were working with polynomial coefficients, Fast Fourier Transforms and convolutions, or modulo arithmetic, you'd prefer zero based arrays. In my experience, the majority of places where math notation uses 1-based arrays are in applications where the index doesn't matter.
I prefer zero based arrays specifically because they are better for doing mathematics. Yeah, it sucks that a lot of matrix algorithms in text books use one based arrays, but I blame the text book for getting it wrong.