News for hackers. Stuff that matters.
Re:Why numbering should start at zero (1982) by benaadams on Thursday December 15, 2016 @02:56PM (#13187692)
Biggest mistake with 0-based arrays is calling it an "index" rather than an "offset"; in terms of offsets 0 makes perfect sense.
Re:Why numbering should start at zero (1982) by zepolen on Thursday December 15, 2016 @04:28PM (#13188584)
I like to think of it like this:

For 0 based indexing the punctuation is the indexes/offsets:

  [    a    ,    b     ,    c    ]
  0         1          2         3
for 1 based indexing consider the actual elements are the indexes/positions:

  [    a    ,    b     ,    c    ]
       1         2          3
In the first case it is non inclusive, ie.

  elements[0:3] - all items between offset 0 and 3
The second case is inclusive, ie.

  elements[1:3] - all items including 1 and 3

Personally I don't have an issue with either, they both 'make sense'

Where they stop making sense is when you'd mix up the inclusivity ie (for the second case).

  elements[1:4] - including item 1 not including 4
Re:Why numbering should start at zero (1982) by jlubawy on Thursday December 15, 2016 @04:13PM (#13188445)
In C it also helps to think of it in the equivalent pointer form:

   p == &(p[0])
   p[0] == *(p+0)
   p[1] == *(p+1)
where p is a pointer to some arbitrary data type. Then it becomes an offset in memory.
Re:Why numbering should start at zero (1982) by mettamage on Thursday December 15, 2016 @03:25PM (#13187983)
Thanks for saying this :) It's things like these that I'd wish people would tell sooner rather than later.
Re:Why numbering should start at zero (1982) by Walkman on Thursday December 15, 2016 @03:17PM (#13187895)
Why didn't you born sooner? :D
Re:Why numbering should start at zero (1982) by mettamage on Thursday December 15, 2016 @03:24PM (#13187970)
I had to laugh really hard at this one. Thanks for making my evening :)
Re:Why numbering should start at zero (1982) by nimos on Thursday December 15, 2016 @04:24PM (#13188545)
I think this would help a lot for people learning computer systems as well. Matches the underlying pointer arithmetic logic. Let's all agree to switch to using offset instead of index?
Re:Why numbering should start at zero (1982) by ieatkittens on Thursday December 15, 2016 @03:11PM (#13187842)
Wow. Everything just changed.
Re:Why numbering should start at zero (1982) by zAy0LfpBZLC8mAC on Thursday December 15, 2016 @03:54PM (#13188293)
That indeed is a very good way to phrase the core of the problem for non-mathematicians, thanks :-)