Hacker News new | ask | show | jobs
by fluidcruft 1250 days ago
I just never find myself working out formulae/series/proofs on paper using zero-indexing. When you look up derivations/solutions in books and references they're one indexed. A recent example was a formula that had a (n-1)!*n! term that made sense from understanding the derivation. But I forgot to code it as (n-2)!*(n-1)! at first.

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.

1 comments

There are good reasons why indexing from zero with exclusive upper bounds should be preferred. I'll defer to Dijkstra for the explanation: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
Because it's intuitive that an array contains an element before the first element?
I have a ruler. What number does the first centimeter start at?
It's a bit like all those people claiming that the new millennium shouldn't have been celebrated until 2001. They didn't stop to think how many years pass between the epoch and the time of interest. You celebrate a baby's first birthday after one year of time has passed. Until that point they are zero (and a bit) years old.
Do you typically measure sets with a ruler?

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

Is this a pithy response? The first element is indexed by zero.
Isn't dropping Dijkstra links as an appeal to authority about 0-indexing considered a pithy response?

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.

We're discussing programming language design. Referencing a prominent computer scientist to explain something on that subject better than I can seems like a reasonable thing to do. If you want to point me to somewhere where it can be argued that indexing from one is useful (not just a matter of aesthetics), please do.
Again, machines are not the purpose of computing.

"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.

That's not a scientific paper.

I find it easier not to make mistakes when I index from 1.

It's a numbered manuscript by Edsger Wybe Dijkstra, one of the most influential members of computing science’s founding generation [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.

[1] https://www.cs.utexas.edu/users/EWD/

[redacted]
Maybe work on your communication skills.