14 ms·
That's not code, that's English. When we start indexing from 0, the only time we need to do a +/- 1 is when we need to index the last element. All other times
by scott_s 17y ago
That's not code, that's English.
When we start indexing from 0, the only time we need to do a +/- 1 is when we need to index the last element. All other times (iterating, mapping) we don't need to.
Also, starting indices at 1 would change the idiomatic iteration to:
for (int i = 1; i <= SIZE; ++i)
I find that the <= and >= operators add more to my cognitive load than the strict relation operators < and > because there's an or in there. I don't find the alternative to that idiom any better:
for (int i = 1; i < SIZE + 1; ++i)
Your original argument was that we should make it easy for humans to understand, not computers. I think that starting indices from 0 is easier for humans to understand because it simplifies the code we must write and read.
- TweedHeads 17y agoNo, your language limitations don't have to force the rest of the world to accept them. As I alreay said, some languages use the simpler construct: For i=1 to N And C could easily use: for(i=1;i==n;i++) just by changing the way the loop condition works. So as you say, it is all about the language.
- jonsen 17y agoNo way I would trust a language design with your semantics for this syntactic construct: for(i=1;i==n;i++)