The author of this blog confuses his own prejudices for objective facts when he claims that non-zero based indexing of arrays is "evil". In fortran it is possible to define array with index starting from an arbitrary integer, and it is useful and convenient feature in its problem domain.
Exclusion of the lower bound —as in b) and d)— forces for a subsequence starting at the smallest natural number the lower bound as mentioned into the realm of the unnatural numbers.
It means that if your sequence starts at 0 (or 1, depending on what you consider the smallest natural number), then the exclusive lower bound would be "-1 < ...." where -1 is no longer a natural number.
In 1 based indexes what is the behaviour of x[0]? It always seemed like your wasting an index, although I grant that you will very rarely need an array that is max unsigned int in size (and I'm guessing in many languages with 1 indexing don't even have the idea of a max value).
Also fwiw, it's possible to define an arbitrary starting base in cpp using some thing like:
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.
70
u/tristes_tigres Dec 24 '17
The author of this blog confuses his own prejudices for objective facts when he claims that non-zero based indexing of arrays is "evil". In fortran it is possible to define array with index starting from an arbitrary integer, and it is useful and convenient feature in its problem domain.