# Indexing from One

With the exception of Matlab (and Octave), which the 1-indexing behavior is inherited from, just about every other programming language indexes arrays from 0. So common is this practice that it's the origin of the claim that mathematicians do not include $$0$$ in the set of natural numbers, but computer scientists do!

Why do computer scientists (and software engineers) like 0-indexing and why does it make more sense? Because it simplifies a lot of index calculations. I personally find a lot of value in 0-indexing, however I imagine the 1-indexing practice was inherited to simplify the migration of Matlab/Octave code into Julia. As great as a bunch of indie languages may be, there's a "dark side" to popularizing a language and it being ultimately accepted by the masses which has a lot to do with who picks it up. The harsh reality is that sometimes design choices may go into a language for the sake of it getting picked up and a lot of Julia's early adopters were Matlab users. I imagine a lot of Matlab users were like, "well, it's super easy for me to pick up Julia because it has all of these features I use and love from Matlab, plus it does all this other great stuff too." This is likely a similar mantra of the adopters which migrated to Julia from Python.

This is one of the few features of Julia which I am not ecstatic about, but I suffer silently because it's the single aspect of the language with which I don't find immense value.

Now, one could also argue that a lot of situations where one ends up doing more complicated index computations should be avoid in Julia as there are often other ways to accomplish such tasks, so the impact should be low. In fact, for most data scientists, one will rarely deal with the challenges associated with 1-indexing. However, when recently writing up the Binary Search post, I was re-introduced to the complications of 1-indexing.

An example is when you're writing crypto code which uses the modulo operator to convert numbers into letters.

std::vector<unsigned long> message = get_message();
std::vector<unsigned long> output;

for (size_t idx = 0; idx < message.size(); idx++) {
output.push_back(alphabet[message[idx] % 26]);
}

Migrating this code into Julia isn't as straight-forward because it will throw an exception everytime I hit a multiple of 26. Instead of that pointing to the first letter of the alphabet, I would need to add a + 1 to line it up properly, which complicates matters a bit.