logoalt Hacker News

cb321yesterday at 12:19 PM2 repliesview on HN

As @SkiFire correctly observes[^1], off-by-1 problems are more fundamental than 0-based or 1-based indices, but the latter still vary enough that some kind of discrimination is needed.

For many years (decades?) now, I've been using "index" for 0-based and "number" for 1-based as in "column index" for a C/Python style [ix] vs. "column number" for a shell/awk/etc. style $1 $2. Not sure this is the best terminology, but it is nice to have something consistent. E.g., "offset" for 0-based indices means "off" and even the letter "o" in some case becomes "the zero of some range". So, "offset" might be better than "index" for 0-based.

[^1]: https://news.ycombinator.com/item?id=47100056


Replies

matkladyesterday at 1:37 PM

Ha! I also use `line_number = line_index + 1` convention!

show 1 reply
throwaway27448yesterday at 1:37 PM

Ordinal is nice because it explicitly starts at 1.

show 2 replies