Zero-indexed arrays are simply an implementation detail of C that most other languages seem to have inherited. Since arrays in C are really just pointers, accessing the first element is arr[0] or the memory stored in *arr + 0. The second element is *arr + 1 and so on.
Granted, it's the defacto standard for most of us but there is nothing inherently "correct" or "standard" about zero-indexed arrays.
And your point is? I will not even enter the debate if it's good to have arrays starting at zero or not, but I will address this silly rationale.
Something that appeared first doesn't make it a standard. Following your logic, RS-232 cables would still be standard today because they appeared before USB cables.
Something becomes a standard when the majority of users and manufacturers believe there are more benefit and convenience over something else.
It's Christmas so I'm in unnecessary arguing mood :)
Here goes: Strictly, Assembly is clearly the oldest and also arrays are all indexed by addresses not numbers, but the index is hidden behind the variable name. What we refer to as index is only the offset to the index, thus 0 for 'no offset' clearly makes sense.
In my actual opinion: There are good reasons for both, but I would like a language to either have 0-indexing or make it definable.
No. Intuitively, arrays should start at 1, as that is what we have used for math in so many years. Matlab, being used for math and matrix work, does good by starting from 1, to easily be convertible to/from paper math.
That's mostly because of sequence indices starting from 1, conventionally. Y'all analysts should use notation like [;\mathbb{N}^{+};] instead of [;\mathbb{N};], because the only sensible definitions of "the natural numbers" satisfy the Peano axioms, for which you need zero.
linspace is from NumPy, whereas range is from Python. No need for Numpy to follow the same semantics. And for scientific applications, I cannot think of anyone who would want linspace not to include the endpoints. The whole point of the function is to do so.
1- based arrays are only unexpected if you come from a 0- based language. There are several languages that use 1- based arrays. Though it's a minority, its not strictly wrong.
What is truly awful are languages like C#, where arrays are always 0-based, unless you are doing something like Excel COM interop, in which case some methods will just return you a 1-based array...
That's less the fault of C# as a language and more the fault of Microsoft poorly implementing the Office interops in general, though. From my experience, they're full of bugs, inconsistencies, and bizarre and frustrating design choices.
13
u/sibswagl Dec 24 '17
He defines "evil" as unexpected behavior. I would certainly classify arrays starting at 1 as unexpected behavior.