News for hackers. Stuff that matters.
Re:Numbering should start at zero: E.W. Dijkstra by Ukv on Friday March 21, 2025 @09:31AM (#43435467)
> Yes, negative indexing as in e.g. Python (so basically "from the end") can be incredibly convenient and works seamlessly when indexes are 0-based.

I'd claim 0-based indexing actually throws an annoying wrench in that. Consider for instance:

    for n in [3, 2, 1, 0]:
        start_window = arr[n: n+5]
        end_window = arr[-n-5: -n]
The start_window indexing works fine, but end_window fails when n=0 because -0 is just 0, the start of the array, instead of the end. We're effectively missing one "fence-post". It'd work perfectly fine with MatLab-style (1-based, inclusive ranges) indexing.

There are no comments on this comment yet.