13/May/2022
- The main reason 0 based indexing is 'the default' is because of C convention
- C only did this for pointer arithmetic (
item_in_array = array_start + type_size * index
) - In general, stop complaining about languages simply because they don't follow c conventions (required semi-colon/no white space based syntax)
- There is no magic philosophical reason why 0 based indexing is better
- People normally count starting with 1, you might not notice but every time you're indexing 0 based arrays you're doing an extra -1 or +1 in your head
- 1 based indexing is good in some reasons:
- The first element, is literally the first element
- To index the last item you don't have to
array[ len - 1 ]
- If the language supports negative indexing, it is more consistent: first = 1, last = -1; instead of first = 0, last = -1