The 0 indexing in python does really and truly suck sometimes though.
The 0 indexing in python does really and truly suck sometimes though.
Now that's something you usually don't hear. At my university I heard a bit of "urban legend" about how back in the day (think early 1990's) a couple of professors got a peer-reviewed article published because they found out that Matlabs 1-indexed implementation of some algorithm resulted in numerical errors, which they measured and corrected. Don't really remember the details, and most of those involved have already retired.
The problem isn't whether 0 or 1 are "right" or not, it's the inconsistency. It makes transcribing something from a textbook harder, because the indexing logic in a textbook algorithm can get quite intricate. It's even worse if they use slices like M[i:j,m:n].
Indexing from 1 is the standard in many areas, going back many decades. SWEs have adopted a different convention.
It is inevitable to have to use both conventions if you do varied math stuff. Thus, you will never be happy.
So you end up having to translate from one-indexed derivations to zero-indexed code and it leads to different bugs. Ultimately zero-indexing just trades one layer of bugs for another.
IMHO zero-indexing makes sense to people thinking about the machine, not necessarily the work people are trying to use the machine to do.
To be fair sometimes the opposite is true and zero-indexing gives less complex expressions.
How about I drop a link about Einstein Notation with a curt observation that there are good reasons it uses both zero and one indexing simultaneously?
As I said it depends on how you are thinking about things. Indexing makes sense to people who are focusing only on the machine.
"The purpose of computing is insight, not numbers." (Hamming)
Machines and notation are both tools. Aesthetics do matter particularly for tools used for thought.
There is no correct answer and imposing one tool's limitations on everything is not useful. Particularly not "just because Dijkstra said so".
Sometimes 0-indexing works well. Sometimes it sucks. Sometimes 1-indexing works well, sometimes it sucks.
I did in fact give you a reference. The fact that it's irrelevant to you and dismissed as merely "aesthetics" and that you think a computer scientist is the domain expert of all science tells me everything that needs to be said--you never deal with questions of correctness beyond mere transcription.
What I said is that moving from Octave/Matlab to python's zero indexing sometimes does truly suck. And I mean it. That doesn't mean 1-indexing never sucks or that I am inaware of Dijkstra's opinions. Having to arange(1, N+1) or 1:N+1 or whatever everywhere isn't eliminating off-by-one errors.
Matlab and Octave and FORTRAN etc are domain languages designed for linear algebra. They are of course going to be more convenient for their domains.
Furthermore it depends on what you're doing with that first centimeter. In many instances the first centimeter is correctly considered to be 0.5
I find it easier not to make mistakes when I index from 1.
The issue stems from the word "index" in the sense of "to count" .. that the first cell is numbered 1 makes sense to some.
What is actually happening is measurement, or the offset from the origin of memory.
The first inch starts at zero on the tape measure and ends at 1, that first inch has an offset of zero.
For all manner of reasons to do with measuring memory as one might measure wood a great many people think in terms of memory offsets.
So every time I see `for i in range(10)`, I have to do the mental computation: I am repeating this operation on numbers from 0,...,9.
I would rather write `for i in range(9)` and know that I am operating on 0,..,9.
Exclusive upper bounds mean slices work neatly: a[0:10], a[10:20], a[20:30] etc. That's very neatly represented in a loop from zero in steps of ten. That pattern turns up all over the place when accessing arrays.
I've spent enough time in MATLAB to have been scarred by that kind of array slicing and off-by-one errors.