Hacker News new | ask | show | jobs
by ilovetux 2209 days ago
I am not sure why being zero-indexed is considered a feature. I have no problem using a zero-indexed system, but I've never really thought of it as a feature. Is there something I'm missing that makes zero-indexed systems faster, easier to use or otherwise better than one-indexed system?
1 comments

There's a better reason than this that I'm forgetting, but never underestimate the power of being the same as what people are already familiar with. Every time I have to write lua or read some Matlab, the mental overhead of having to remember everything is one-indexed is just incredibly annoying.
Anyone used to command-line tools is used to fields being 1-indexed.

awk uses $0 as the whole line, and $1 as the first field. cut uses -f1 as the first field $1 is the first argument to a posix shell script /1 is the first matched reference in a sed $1 is the first regex match in perl

A command-line tool being 0-indexed breaks from expectation of what everybody is used to using on the command line.

Anyone is a generalization based on a narrow viewpoint. I would say I am pretty used to command-line tools at this point, at least enough to be using linux as a daily driver comfortably. And I frankly I didn't know 1-indexed fields were the norm, even though I knew $1 is the first argument to a poxis shell script (I always assumed $0 referred to the script or command itself).
That's fair, I overgeneralized.
I get what you're saying, but to be more general I'd argue that's just 0 indexing with the API specifying what's in what index.

I'd more "formally" define 0/1 indexing as:

Zero indexing: arr[0] is a valid way to address the first element of an array, and len(arr) - 1 is the index to the final element.

One indexing: arr[0] results in an error or an out of bounds access, and len(arr) is the index to the final element.

These statements are true in Matlab, but not most command line tools.