by void_mint · 5y ago · 0 comments
One example is when you're processing arrays or matrices in blocks. Using right-open intervals (also the most elegant option) you end up with intervals like [0, 4) [4, 8) [8, 12). Pretty trivial to calculate those bounds! It's just 4N.
With 1-based you end up adding and subtracting 1 all over the place.
Another example is indexing into flattened arrays. To get to the relevant element it's just (row_len * col + row). With 1-based indices it's (row_len * (col - 1) + row).
Basically I've done a lot of 1-based programming (in Matlab), and you definitely end up adding and subtracting 1 in places where you wouldn't need to with 0-based programming.
No...You can feel like something is elegant. Others may not feel that way. Saying "This is elegant" doesn't explain why, and since it's totally subjective it's just kind of a meaningless thing to say. Similar to measuring something by how "interesting" it is.
The rest of your post just verifies that your original post should've been "I just like it more."