As the title suggests, the arrays of many programming languages start counting from zero. For example, in JavaScript, write a simple array and get the value with index zero:
const 水果 = ["香蕉", "苹果", "桃子"];
console.log(水果[0]);
This will return "香蕉". The popularity of this design can often be traced back to C language. Although C language is considered a high-level language, it still has many features of low-level languages for the sake of performance. The essence of an array in C language is a pointer to a memory address, and the number represents the offset value. Therefore, 0, which has no offset, represents the first one, i.e. 0 = 1.
Later, many high-level languages used the concept of index to represent array numbers, but influenced by C language, they also followed the “starting from zero” convention. Only a few marginal languages, such as Lua and MATLAB, use array numbers starting from 1, i.e. 1 = 1.
Therefore, programmers are not necessarily used to counting from zero, but because of historical inertia, they have to continue using this somewhat counter-intuitive counting method. But since this is just historical inertia, there are some contradictions, such as code line numbers.
The default settings of most editors and the specifications of languages all start code line numbers from 1. For example, Python’s error reports can only find the corresponding errors on editors that start line numbers from 1, i.e. 1 = 1.
However, the programming language mlog in the game Mindustry uses line numbers starting from zero and has practicality, because it needs to specify the exact line number when executing the jump (goto) instruction, i.e. 0 = 1.
This mixed situation of 0 = 1 and 1 = 1 can be a bit confusing. Therefore, some users of VSCode editors wanted to enable support for zero-based line numbers in its settings and initiated a feature request. However, developers from Microsoft closed this feature request on the grounds that other editors did not support this feature. This shows that historical inertia has a great influence on these issues…
Inspiration and some content are from the video by Bilibili UP host “原子能” (Atomic Energy)《那些无解的计算机问题【让编程再次伟大#16】》(“Those Unsolvable Computer Problems [Making Programming Great Again #16]”).