array indexing and range for #7470
Replies: 2 comments 1 reply
-
https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html |
Beta Was this translation helpful? Give feedback.
-
Thank you Alex for pointing me to that document. I respect the thoughts/arguments of E. W. Dijkstra; and yours alike. But it is not because Dijkstra thinks we should start considering zero as a most natural number that this is how most people think. Note that devs are taught to do so. My wondering merely stems from the viewpoint that nowadays efforts are made to make it easier for the dev to see code in a way that better reflects 'natural language' (and common reasoning?). Trying to get code more 'speak' the language of the domain. And the array indexing seems archaic and counternatural to me in that regard. But I understand it is more efficient/appropriate in certain domains (math, system programming, ...). But I still think the ".." (exclusive) syntax with the range for is not the best choice in that regard. Because this is neither an index nor an offset, but simply a counter. That is why I proposed to also allow the "..." (inclusive) operator with for, because to me it better reflects the 'counter' aspect. (If you think that could be useful, I can add it as an Idea type discussion.) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I keep wondering why languages insist devs start array indexing at zero.
I understand it has to do with optimizing the calculation of the offset in an array to access elements randomly (avoiding a -1 operation each time).
But couldn't the compiler take care of that -1 operation?
Something similar about the ".." in "for i in 0 .. 5" (excl. upper limit). Why not do the same as the "..." (incl. upper limit) in the match statement? Or why not simply also allow the "..." with for?
To me these seem like some underlying technical problem bleeding thru to the 'user'.
Beta Was this translation helpful? Give feedback.
All reactions