Live data from Hacker News

Why numbering should start at zero (1982)

cs.utexas.edu

71–72 of 72 posts

Re: Why numbering should start at zero (1982)

#71
post #19

Earlier quoted context omitted.

Intuition is the name we give to what we learned early. 0 and 1 are both perfectly fine starting points. They both have advantages and disadvantages. 0 is more common since a lot of languages use C as a starting point in some fashion. C chose 0 because then it can create syntactic sugar for sequential memory access via pointers. Or arrays.

No, C got that from B that got it from BCPL, which has that notation to compile faster: http://exple.tive.org/blarg/2013/10/22/citation-needed/

Nice. It goes deeper than I've been told.

Re: Why numbering should start at zero (1982)

#72
post #23

When I was learning QBasic some billion years ago I recall that I was happy with arrays generally starting at 1 (even though this is user specified in Basic). When I learned C I initially wasn't thrilled about re-learning arrays, but eventually grew to only like 0-based arrays. I'm thinking this is like people who drink coffee will cite studies saying it is good for you, and people who hate it will cite opposite stud…

my @arr = (1, 2, 3); for my $i ($[...$#arr) { ... } It is however, advised not to change $[.

And of course, there's Ada where you can use 'First and 'Last.
Post reply on HN