I notice almost all defenses of 1-based indexing are purely based on arbitrary cultural factors or historical conventions, e.g. “that’s how it’s done in math”, rather than logical arguments.
Numbering should start at zero (1982)
41–50 of 309 posts
Re: Numbering should start at zero (1982)
#421 or 0-based index... I recently picked up Lua for a toy project and I got to say that decades of training with 0-based indexes makes it hard for me to write correct lua code on the first try. I suppose 1-based index is more logical, but decades of programming languages choosing 0-based index is hard to ignore.
Why?
Re: Numbering should start at zero (1982)
#43 Numbering should start at π (2025) (umars.edu)
Seriously, it all depends on whether u're counting the items themselves (1-based) or the spaces btwn them (0-based).
The former uses natural numbers, while the latter uses non-negative integersFor instance, when dealing with memory words, do u address the word itself or its starting location (the first byte)?
The same consideration applies to coordinate systems: r u positioning urself at the center of a pixel or at the pixel's origin?
Almost 2 decades ago I designed an hierarchical IDs system (similar to OIDs[1]). First I made it 0-based for each index in the path. After a while I understood that I need to be able to represent invalid/dummy IDs also, so I used -1 for that. It was ugly - so I made it 1-based, & any 0 index would've made the entire ID - invalid
---
Re: Numbering should start at zero (1982)
#44I appreciate Dijkstra's arguments, but the fact remains that no non-technical user is ever going to jibe with a zero-indexed system, no matter the technical merits. Languages aimed at casual audiences (e.g. scripting languages like Lua) should maybe just provide two different ways of indexing into arrays: an `offset` method that's zero-indexed, and an `item` method that's one-indexed. Let users pick, in a way that's…
Re: Numbering should start at zero (1982)
#45I appreciate Dijkstra's arguments, but the fact remains that no non-technical user is ever going to jibe with a zero-indexed system, no matter the technical merits. Languages aimed at casual audiences (e.g. scripting languages like Lua) should maybe just provide two different ways of indexing into arrays: an `offset` method that's zero-indexed, and an `item` method that's one-indexed. Let users pick, in a way that's…
Re: Numbering should start at zero (1982)
#46At least we're not stuck with the Roman "inclusive counting" system that included one extra number in ranges* so that e.g. weeks have "8" days and Sunday is two days before Monday since Monday is itself included in the count.
Re: Numbering should start at zero (1982)
#471 or 0-based index... I recently picked up Lua for a toy project and I got to say that decades of training with 0-based indexes makes it hard for me to write correct lua code on the first try. I suppose 1-based index is more logical, but decades of programming languages choosing 0-based index is hard to ignore.
Re: Numbering should start at zero (1982)
#48Earlier quoted context omitted.
It makes more sense if you think of indices as pointing between elements: 0 1 2 3 4 ----------------- | A | B | C | D | ----------------- -4 -3 -2 -1 -0 Except, of course, -0 doesn't exist. AFAIK that's why C# chose to add a special "index from end" operator, `^`, instead of using negative indices.
> Except, of course, -0 doesn't exist. Not for integers on modern hardware. If only hardware used ones’ complement ( https://en.wikipedia.org/wiki/Ones'_complement)… ;-) Meanwhile, the workaround is to use -1 through -5 to index from the end of the array.
Re: Numbering should start at zero (1982)
#49I appreciate Dijkstra's arguments, but the fact remains that no non-technical user is ever going to jibe with a zero-indexed system, no matter the technical merits. Languages aimed at casual audiences (e.g. scripting languages like Lua) should maybe just provide two different ways of indexing into arrays: an `offset` method that's zero-indexed, and an `item` method that's one-indexed. Let users pick, in a way that's…
There is no good reason to cater to non-technical users when designing programming languages. In what way is Lua “aimed at casual audiences”?
"one of the design goals, was for Lua to be easy for nonprogrammers to use"
[1] https://www.reddit.com/r/lua/comments/w8wgqb/complete_interv...
Re: Numbering should start at zero (1982)
#50The 1980s were not a particularly enlightened time for programming language design; and Dijkstra's opinions seem to carry extra weight mainly because his name has a certain shock and awe factor. It isn't usual for me to agree with the mathematical convention for notations, but the 1st element of a sequence being denoted with a "1" just seems obviously superior. I'm sure there is a culture that counts their first fing…
For math too, 0-based indexing is superior. When taking sub-matrices (blocks), with 1-based indexing you have to deal with + 1 and - 1 terms for the element indices. E.g. the third size-4 block of a 16x16 matrix begins at (3-1)*4+1 in 1-based indexing, at 2*4 in 0-based indexing (where the 2 is naturally the 0-indexed block index). Also, the origin is at 0, not at 1. If you begin at 1, you've already moved some dista…