4 ms·
Biggest mistake with 0-based arrays is calling it an "index" rather than an "offset"; in terms of offsets 0 makes perfect sense.
by benaadams 10y ago
Biggest mistake with 0-based arrays is calling it an "index" rather than an "offset"; in terms of offsets 0 makes perfect sense.
- ieatkittens 10y agoWow. Everything just changed.
- Walkman 10y agoWhy didn't you born sooner? :D
- mettamage 10y agoI had to laugh really hard at this one. Thanks for making my evening :)
- mettamage 10y agoThanks for saying this :) It's things like these that I'd wish people would tell sooner rather than later.
- zAy0LfpBZLC8mAC 10y agoThat indeed is a very good way to phrase the core of the problem for non-mathematicians, thanks :-)
- jlubawy 10y agoIn 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.
- deleted 10y ago[deleted]
- nimos 10y agoI 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?
- zepolen 10y agoI 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