Hacker News new | ask | show | jobs
by dragonwriter 2797 days ago
> Addressing an element T[h][w][c] in a linearized 3D tensor with 0-based indexing:

But why would you ever use linearized addressing when you have proper multidimensional access? Aside from doing the low-level implementation of multidimensional access, you shouldn't ever need to do that.

> Or let's say you want to take a string "abc" and repeat it until the length is 10, getting "abcabcabca". With 0-based indexing

Your example assumes not only the stated indexing model but also a range function that returns the integer members of a half-open range, which is a little crazy of a way to do loops, but the least unintuitive way with 0-based indexing, so programmers are used to it from C (where you do it without an actual function call) and newer zero-based languages.

With 1-based languages, the sane way is the more intuitive closed range (for i in 1:5) which doesbt require an extra mental operation to convert to the set of values that will actually be used. There are good uses for half-open ranges, but the kind of explicit loop control they get used for in 0-based languages is an artifact of 0-based languages, so arguing that it is (even more) awkward in a 1-based language isn't an argument against 1-based languages.