this post was submitted on 16 Jul 2023
712 points (92.4% liked)

Programmer Humor

32061 readers
1393 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

No offence

you are viewing a single comment's thread
view the rest of the comments
[–] Faresh@lemmy.ml 1 points 1 year ago

I haven't worked with any 1-based indexing languages, but I can't really see how it could be problematic. The only advantage I see about 0-based indexing is the simplicity in how the memory address is calculated. Just arr + index × sizeof(member) which I think even has its own MOV instruction on x86. But besides that I can't see any more advantages. With 1-based indexing I see the advantage of the number of elements also being the index of the last element of the array, avoiding off-by-one errors when writing. Though, again, I've never used a 1-based indexing language.