Numbering should start at zero (1982)

Zero-based vs one-based in programming practice

  • Many argue zero-based indexing is more “natural” for programming because array indices correspond directly to pointer offsets: a[i] == *(a + i). One-based requires a -1 adjustment or compiler work.
  • Others counter that high-level languages don’t need to mirror hardware, and 1-based can be more intuitive for humans and certain data structures (e.g., heaps: children at 2i and 2i+1 with root at 1).
  • Scientific and numerical languages (Fortran, Matlab, R, etc.) using 1-based are cited as evidence that 1-based can be performant and convenient. Zero-based is seen as dominant in systems languages.
  • Several note that in idiomatic high-level code you rarely should do explicit index arithmetic at all; iterators and slices avoid most off-by-one issues.

Negative and end-relative indexing

  • Zero-based indexing interacts awkwardly with negative indexing and slicing in languages like Python: l[-n:] and cases involving -0 reveal missing “fenceposts”.
  • Some prefer explicit “index-from-end” operators (like C#’s ^) over negative indices to avoid ambiguity and the lack of -0.

Offsets, ordinals, and terminology

  • A recurring theme: distinguish offsets (0-based, spaces between items) from ordinals (1-based, items themselves).
  • Proposals include separate words for zero- vs one-based indexing (offset vs ordinal, “0ndex/1ndex”, etc.), but consensus is that “zero-based/one-based” remains clearest.
  • Debate on whether 0 is a “natural number” spills into Peano axioms and set-theoretic foundations; participants note this is convention-dependent across fields and languages.

Real-world analogies and human intuition

  • Elevators, floors, ages, days, and music intervals are used as examples: some domains are implicitly 0-based (tape measures, modular arithmetic, time spans), others 1-based (pages, “first” floor in some countries, scale degrees in music).
  • Several argue that people’s sense that 1-based is “more intuitive” is largely cultural and linguistic, not logical.

Views on Dijkstra’s note

  • Some see the note as a compelling, almost definitive argument that 0-based is mathematically cleaner (especially for ranges like 0 ≤ i < N).
  • Others criticize it as stylistically proof-like but ultimately resting on subjective notions of “niceness,” and note that there are important cases (reverse loops, unsigned indices, human-facing APIs) where 1-based may be simpler.