logoalt Hacker News

LoganDark • yesterday at 8:34 PM • 1 reply • view on HN

I think it's inclusive indexing in general that make reverse iteration nice, not necessarily whether it's based on 1 or 0. (Namely, an ergonomic way to access the index of the last element as opposed to the length of the list. With inclusive indexing, the length is already naturally the index of the last element.)


Replies

ufo • yesterday at 11:33 PM

For sure, but 0-based indexing often goes hand in hand with half-open intervals [0,n). One might even argue that a special way to access the "last index" is as unergonomic as just typing "length - 1"