It's a C family (predecessors and descendants) idiosyncrasy that very unfortunately got out of hand. Most other old languages had either 1-based indexing or were agnostic. Most notably FORTRAN, which is the language for numerical calculations is 1-based.
The seminal book Numerical Recipies was first published as 1- based for FORTRAN and Pascal and they only latter added a 0-based version for C.
Personally, coming from Pascal, I think the agnostic way is best. It is not only about 0-based or 1-based but that the type system encodes and verifies the valid range of index values, e.g. in Pascal you define an array like this:
temperature = array [ -35 .. 60 ] of real;
You will get an immediate compule-time error if you use
temperature[61];
At least with Turbo Pascal you could chose if you wanted run-time checks as well.
I have a hard time wrapping my head around the fact that this feature is pretty much absent from any practically used language except ADA.
It's a C family (predecessors and descendants) idiosyncrasy that very unfortunately got out of hand. Most other old languages had either 1-based indexing or were agnostic. Most notably FORTRAN, which is the language for numerical calculations is 1-based.
The seminal book Numerical Recipies was first published as 1- based for FORTRAN and Pascal and they only latter added a 0-based version for C.
Personally, coming from Pascal, I think the agnostic way is best. It is not only about 0-based or 1-based but that the type system encodes and verifies the valid range of index values, e.g. in Pascal you define an array like this:
You will get an immediate compule-time error if you use At least with Turbo Pascal you could chose if you wanted run-time checks as well.I have a hard time wrapping my head around the fact that this feature is pretty much absent from any practically used language except ADA.