3 ms·
I believe it’s a practicality to simplify pointer arithmetic
by tacitusarc 1y ago
I believe it’s a practicality to simplify pointer arithmetic
- Ygg2 1y agoYes but why does no one talk here about fighting the 0 indices. Or how they are switching to Lua, because 0 indices are hard? Am I the only person that remembers how hard it was to wrap your head around numbers starting at 0, rather than 1?
- m-schuetz 1y agoI find indices starting from zero much easier. Especially when index/pointer arithmetic is involved like converting between pixel or voxel indices and coordinates, or indexing in ring buffers. 1-based indexing is one of the reasons I eventuallz abandoned Mathematica, because it got way too cumbersome. So the reason why you don't see many people fighting 0-indexing is because they actually prefer it.
- scott_w 1y agoYes, I think you are. The challenges people describe with Rust look more difficult than remembering to start from 0 instead of 1…
- Ygg2 1y agoI don't think so. One based numbering is barring few particular (spoken) languages the default. You have to had to change your counting strategies when going from regular world to 0 based indices. Maybe you had the luck of learning 0 based language first. Then most of them were a smooth ride. My point is you forgot how hard it is because it's now muscle memory (if you need a recap of the difficulty learn a program with arbitrary array indexing and set you first array index to something exciting like 5 or -6). It also means if you are "fighting the borrow checker" you are still at pre-"muscle memory" stage of learning Rust.
- scott_w 1y ago> Maybe you had the luck of learning 0 based language first. Then most of them were a smooth ride. Given most languages since at least C have 0-based indexing... I would think most engineers picked it up early? I recall reading The C Programming Language 20 years ago, reading the reason and just following what it says. I don't think it's as complex as the descriptions people put forward of "fighting the borrow checker." One is "mentally add/subtract 1" and another is "gain a deep understanding of how memory management works in Rust." I know which one I'm going to find more challenging when I get round to trying to learn Rust...
- Ygg2 1y ago> Given most languages since at least C have 0-based indexing. As I mentioned I started Basic on C64, and schools curriculum was in Pascal. I didn't learn about C until I got to college. > One is "mentally add/subtract 1" and another is "gain a deep understanding of how memory management works in Rust." In practice they are, you start writing code. At first you trip on your feet, read stuff carefully, then try again until you succeed. Then one day, you wake up and realize I know 0 indices and/or borrow checker. You don't know how you know, you just know you don't make those mistakes anymore.
- scott_w 1y agoI literally just described my process, so I don’t get how you got to “you don’t know how you know” because… well… I just told you. Also, there’s a huge difference between beginners not understanding 0-based indexing and experienced C++ engineers describing the challenges understanding Rust’s unique features. I mean, Jesus Christ, we’re commenting on a thread here of experienced engineers commenting on how challenging it can be! I really don’t know what else to say.
- Ygg2 1y ago> Also, there’s a huge difference between beginners not understanding 0-based indexing and experienced C++ engineers describing the challenges understanding Rust’s unique features Keep in mind I wasn't new to programming at that point. I was programming in C64 basic for 3 years and Pascal for 3 as well. For hobby of course, and not fully. Zero indexes aren't simple, they are intertwined everywhere but they are easy - as in familiar. What experienced C++ devs in Rust are not much different than experienced Pascal devs in C. Lost. And having to rethread semi-familiar grounds. --- And I described you my own. I don't fight the borrow checker. I just intuitively know how it works and what to avoid. If you think just subtracting one or adding one is enough, there should be an easy enough way to test if it is. In Veritasium video they mention that having glasses that turn your vision upside down will cause confusion at first, but you will get used to them quickly. What you could do is take a language that has arbitrary starting index value and set it to something weird. Like 42 or -5. Then rewrite your programs. See how many off by 41 errors you make. Then once you no longer make mistakes with it. Go back to 0 indexes.
- jthill 1y agoFor languages with 0-based array element numbering, say what the numbers are: they're offsets. 0-based arrays have offsets, 1-based arrays have indices.
- WalterBright 1y ago> 0 indices are hard? I started out with BASIC and Fortran, which use 1 based indices. Going to C was a small bump in the road getting used to that, and then it's Fortran which is the oddball.
- Ygg2 1y agoInteresting path. I went Basic, and Pascal and then C in college. Honestly it was such a mind twist.
- int_19h 1y agoMost oldschool BASIC dialects (including the original Dartmouth IIRC) use 0-based indices, though. It's the worst of both worlds, where something like: DIM a(10) actually declares an array of 11 elements, with indices from 0 to 10 inclusive. I believe it was QBASIC that first borrowed the ability to define ranges explicitly from Pascal, so that we could do: DIM a(1 TO 10) etc to avoid the "zero element tax"