6 ms·
Hear hear. Everyone that's making excuses for one based is wrong. You need a zero in your set of integers to form a Ring modulo N. I hereby declare everyone
by gct 8y ago
Hear hear. Everyone that's making excuses for one based is wrong. You need a zero in your set of integers to form a Ring modulo N. I hereby declare everyone that wants 1 based indexing out of some naive sense of it being easier a scrub.
- currymj 8y agoaesthetically i sort of agree, but i just want to type in equations from papers without having to do any error prone arithmetic — it is slightly less frustrating.
- psychometry 8y agoThat's so absurd I hope it's satire. Humans instinctively reason about iteration in terms of the natural numbers, not the semantic purity of the underlying abstract algebra.
- 0-_-0 8y agoIt's not absurd at all. In situations where you need to do modulo arithmetic on array indices 1-based indexing forces you to shift the offset by 1.
- psychometry 8y agoYes and that's something most programmers need to do almost never, so let's not make any important design decisions around that very specific case.
- 0-_-0 8y agoDo you suggest that we appeal to tradition instead of practical considerations?
- 3JPLW 8y agoOr, you know, just use the `mod1` function in those cases: https://docs.julialang.org/en/v1/base/math/index.html#Base.mod1 https://docs.julialang.org/en/v1/base/math/index.html#Base.m... . Even more fun is that you can use the special `end` index to implement a stupid-simple circular index: `A[mod1(i, end)]` will always be in-bounds for integer `i`. It's not a common case, though. Using inclusive ranges and 1-based indexing makes Julia's slicing syntax use first-class ranges that can behave like arrays themselves. You can do math on them. You can do all sorts of amazing things that make your life easier: https://julialang.org/blog/2016/02/iteration https://julialang.org/blog/2016/02/iteration Sometimes you want to count fenceposts, and sometimes you want the distance (e.g., offset) from the first post. Keep this imagery in mind and it's easy to do either in any language.
- gct 8y agoTotally serious, languages should have a single indexing scheme, and it should start at 0. All other choices make you a Toilet Person.
- dnautics 8y agomaybe sometimes you want to be really clear that there is a well order with no additive inverse.