5 ms·
> 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 l
by dr_zoidberg 4y ago
> 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.
- ogogmad 4y agoWhat you've said isn't surprising. 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.
- enriquto 4y agobut this depends a lot on the particular formula. For example, if you use discrete Furier transforms, all formulas are natural with 0-indexing, but weird with 1-indexing. In general, when the indices of an array are to be interpreted as modulo N, you want them to be 0, 1, ..., N-1 It is inevitable to have to use both conventions if you do varied math stuff. Thus, you will never be happy.
- ethbr0 4y ago(Obligatory) There are only 2 hard problems in computer science: cache invalidation, naming things, and off-by-one errors
- fluidcruft 4y agoI 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.
- hgomersall 4y agoThere 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/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- fluidcruft 4y agoBecause it's intuitive that an array contains an element before the first element?
- hgomersall 4y agoIs this a pithy response? The first element is indexed by zero.
- fluidcruft 4y agoIsn'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.