Is “Array[1]” the first element or second element in the array

arrayindexingprogramming practices

Following the reading of the question Why are zero-based arrays the norm?, I wonder about the terms to use for referring to specific array elements, in the perspective of linguistic reading of programming.

Should Array[1] be called the first element of Array or the second element? In the latter case, then how should the 0th element be referred to?

Best Answer

Programming languages:

Array[1] uses an implicit mapping between the index 1 a specific array element.

This mapping is language specific. Many languages start at 0, some at 1. Some languages allow to start at an other offset. Some language implement sparse arrays. Some languages don't have general purpose arrays as a fundamental data structure and use list and mappings instead.

Linguistics:

The word "first" is an ordinal. So, when you say "the first element", you don't mean the element number 1, but you mean the element that is at the start of the ordered sequence of elements.

Every programmer will therefore map "first" to what is really the first element in the mapping he knows (e.g. Array[0] if the indexing is zero based and Array[1] if indexes start at 1).

Algorithms:

Many algorithms use the word "first" in a language neutral description. So I think your question is definitively relevant in scope of software engineering, even if it's about linguistic.

Related Topic