I'm not a fan of 1-indexed langs even though I use them but...

Semantically "index" should start at 1 since it's numbering (ordering) the elements of a set.

The thing is, what most programmers usually mean by "index" is actually a memory "offset" which obviously starts at 0.

A[0] is the same as *(A)

A[1] is the same as *(A+1)

The popularization of C like pointer arithmetics has contributed to this historic new concept of "index" which starts at 0.

Regardless of preference, off-by-1 errors will keep happening forever even if it's AI writing all the code 🤭

Reply to this note

Please Login to reply.

Discussion

I use 0-based indexing even in math, it just makes more sense to my mind at this point.