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.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Don't all the languages geared towards science and math use 1-based indexing?
And why array indices start at 0 instead of 1, in many, though not all, programming languages.
Indexes should start at one in all languages IMO.The zero thing is a historical quirk due to pointer arithmetic.
Does 1-based indexing have any advantage, beyond familiarity to scientists?
1 instead of zero index based languages such as e.g Julia therefore remove a LOT of cognitive overhead.
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
1-based vs 0-based indexing is such a tired controversy.
There are others that actually like 1-based indexing languages.
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
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