Recently, I wrote an article about why programming languages tend to use zero-based indexing. At least in my experience, the vast majority of programming languages do. Of course, that got me wondering: how many programming languages actually index by one? That’s the topic of today’s article.
Table of Contents
What Is Indexing?
If you clicked on this article, chances are you’re already familiar with the concept of indexing. That said, for completeness, let me take a moment to talk it out.
Any time we’re working with a linear data structure like a list or array, we’re likely able to poke around that data structure using an index. For simplicity, an index is a key into a list. Usually, we use integers, but I suppose you could use anything.
Of course, if we’re going to number items in a list, we have to agree on a convention. Specifically, what do we number the first element? This question typically raises one of three possible answers:
- Start at 0
- Start at 1
- Start at anything else
Because most programming languages start from zero, you might be surprised to hear that there are actually languages that start from one. The two that come to mind for me are Lua and MATLAB. As it turns out, those languages aren’t alone. In the next section, I’ll share a list of languages that index from one.
Programming Languages With One-Based Indexing
As someone who has worked with a lot of programming languages, I find this kind of task to be right up my alley. That said, I don’t claim to be an expert on this topic. As a result, with each programming language I list out, I’ll also share some sources that can back me up.
Ultimately, there are not many languages with indexing from one, but there is a somewhat common thread for the languages that do: math. It seems that many of the languages that prioritize math is some form (e.g., MATLAB, Julia, Mathematica, etc.) all use one-based indexing.
Why Should We Care?
At the end of the day, it doesn’t really matter how a programming language approaches indexing. In the past, it had bothered me how much zero-based indexing confused students, so I struggled to pick a side. These days I’ve realized it doesn’t really matter. Though to some folks, it really does matter, and those are folks you probably don’t want to spend your time with:
All I can say is this guy must be really fun at parties.
At any rate, that’s all I have to share about one-based indexing. If you enjoyed this article, here are some more like it:
- IndexError: String Index out of Range
- How to Check if a String Contains a Substring in Python: In, Index, and More
- Be Careful with String’s Substring Method in Java
And if you really enjoyed this article, why not show your support? Otherwise, I’ll see you next time!
Continuing in our computer science problem series, I figured we'd dive into a couple of fun Java topics: parameter passing and primitive types. Specifically, we'll be looking at whether or not you...
Today, I'm kicking off a series of new articles that take a look at real computer science multiple choice questions and attempt to give some tips for solving them. Right now, I want to start by...