0-Based vs 1-Based Indexing

Cluster centers on debates about zero-based versus one-based array indexing in programming languages, highlighting historical reasons, mathematical intuition, and preferences in scientific computing languages like MATLAB, Julia, R, and Fortran versus general-purpose languages.

📉 Falling 0.4x Programming Languages
2,935
Comments
20
Years Active
5
Top Authors
#8921
Topic ID

Activity Over Time

2007
2
2008
5
2009
41
2010
21
2011
90
2012
43
2013
157
2014
84
2015
86
2016
206
2017
134
2018
231
2019
165
2020
228
2021
398
2022
440
2023
220
2024
137
2025
244
2026
3

Keywords

e.g LOT www.cs IMO SQL ordinal.html EWD831 stanford.edu EWD MATLAB indexing based array languages zero matlab index arrays indexes length

Sample Comments

HappySweeney Dec 4, 2023 View on HN

Don't all the languages geared towards science and math use 1-based indexing?

fuzztester Mar 20, 2024 View on HN

And why array indices start at 0 instead of 1, in many, though not all, programming languages.

fire_lake Dec 27, 2024 View on HN

Indexes should start at one in all languages IMO.The zero thing is a historical quirk due to pointer arithmetic.

ced Feb 18, 2012 View on HN

Does 1-based indexing have any advantage, beyond familiarity to scientists?

The_rationalist Jan 13, 2022 View on HN

1 instead of zero index based languages such as e.g Julia therefore remove a LOT of cognitive overhead.

socialdemocrat Feb 13, 2021 View on HN

Most math books are written in a way where 1 is the first element. So if you take math examples and translate to code, it works more naturally.Also this is how you talk normally. You don't talk about the zeroth-column or zeroth-row in daily speech. You talk about first column and first row.Only reason 0 based indexing make sense to me is because I began programming as a teenagers and was forced to get accustomed to it. But I remember struggling with it. Yes when working with memory, p

topaz0 Sep 29, 2022 View on HN

1-based vs 0-based indexing is such a tired controversy.

pjmlp Oct 23, 2018 View on HN

There are others that actually like 1-based indexing languages.

FridgeSeal Feb 13, 2021 View on HN

Zero based indexing came from early requirements to address things in arrays using offsets.Subsequent languages don’t have this issue, and when you think about it, it causes a weird disconnect: 1-based indexing corresponds exactly with how you think about and see elements in a collection. 0 based indexing-despite how comfortable one gets with it requires additional arithmetic.It’s a relic from the past, and unless you’re doing the very specific thing of indexing via offset instead of posit

umanwizard Dec 14, 2024 View on HN

I have a really hard time understanding why people like 1-based indexes! 0 is the smallest unsigned integer in every programming language I know of that supports the concept of unsigned integer. Why shouldn’t an array at the smallest possible index correspond to the beginning of the array?It’s also very natural to think of arr[i] as “i steps past the beginning of arr”. With one-based indexing arr[i] has no natural interpretation that I know of. It’s “i-1 (for some reason) steps past the begin