News for hackers. Stuff that matters.
Re:Numbering should start at zero: E.W. Dijkstra by branko_d on Friday March 21, 2025 @08:50AM (#43435025)
0-based indexing aligns better with how memory actually works, and is therefore more performant, all things being equal.

Assuming `a` is the address of the beginning of the array, the 0-based indexing on the left is equivalent to the memory access on the right (I'm using C syntax here):

  a[0] == *(a + 0)
  a[1] == *(a + 1)
  a[2] == *(a + 2)
  ...
  a[i] == *(a + i)
For 1-based indexing:

  a[1] == *(a + 1 - 1)
  a[2] == *(a + 2 - 1)
  a[3] == *(a + 3 - 1)
  ...
  a[i] == *(a + i - 1)
This extra "-1" costs some performance (through it can be optimized-away in some cases).
Re:Numbering should start at zero: E.W. Dijkstra by hn_throwaway_99 on Friday March 21, 2025 @09:35AM (#43435518)
The comment you are replying to essentially said exactly that:

> but always assumed it traces back to memory offsets in an array rather than any principled stance because 0-counting sequences represents a crazy choice.

Re:Numbering should start at zero: E.W. Dijkstra by goatlover on Friday March 21, 2025 @01:02PM (#43438203)
But then again Fortran proceeded C, is known for being very performant, and is 1-based by default.