4

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?

  • 1
    It's more between mathematics (subscripts of matrices, which are 2D arrays), and computer science (pointer arithmetic, specifically the ambivalence toward pointer values and the differences (subtractions) between pointer values). Linguistics probably did not play any role at all. – rwong Dec 3 '17 at 7:01
  • 5
    Different programming languages define it differently. Some start with 0 others with 1. – whatsisname Dec 3 '17 at 7:54
  • In zero-based arrays, I call it the second element, because... it's the second element. If I'm talking explicitly about indices and think there's confusion, I sometimes refer to it as the "oneth" element (not "first", that's the zeroth element) - this works fine for the first few in English but breaks down at the 4th/fifth element (Index[4]). – jonrsharpe Dec 3 '17 at 9:12
  • Agreed that it breaks down at 4, but can still work if you emphatically pronounce four ‘Eth as two syllables. – Matthew James Briggs Dec 3 '17 at 9:19
  • Indeed, many algorithms that are implemented with arrays are described in a language neutral fashion, using the terms "first", "second" and so on. – Christophe Dec 3 '17 at 15:12
7

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.

3

It is a fallacy to think of programming languages in terms of linguistics.

They are not natural languages.

In each programming language it is clearly defined which is the first element in an array after each operation. In some languages you can even declare arrays that start on different indices like [3..50].

It is simple in the context of the actual language discussed to understand the concept of the first element.

And what would you called the element fetched by the call to the method First?

  • Sorry, but if it would be a fallacy to think of linguistics in programming, can you explain why so many successful books (for example R.C. Martin's Clean Code) devote do much space to naming conventions, and producing readable code ? For example, if one says that methods should start with a verb and properties a noun, isn't this somehow linked to linguistic concepts ? By the way, did you know that the formal grammars used by all compiler builders were invented by a linguist looking to understand natural language principles ? en.m.wikipedia.org/wiki/Chomsky_hierarchy – Christophe Dec 3 '17 at 12:05
  • @Christophe What you write is something I have known since the mid 80s. You do know that using formal grammars for analyzing natural languages is still failing? Not one spellchecker, autocorrector or grammar analysis program made so far is even close to do the job decently. Astronomy developed from astrology should we still think of astronomy on that basis? – Bent Dec 3 '17 at 13:20
  • The goal of linguists is not to do NLP parsing but to better understand language structures. So the relation between linguistic and computer science isn't exactly the kind of relation between astrology and astronomy. It's more like the relation between computer science and math, or computer science and physics. What I wanted to say is that multidisciplinary thinking helps to advance by finding synergies between disciplines, and that it's always lost energy to focus only on the antagonisms. – Christophe Dec 3 '17 at 14:07
  • Larry Wall would fight you over this answer – whatsisname Dec 3 '17 at 18:16
0

I think the confusion arises by mix interpretation of indices:

Ordinal: which is usually how they are interpreted, the ordered numbered element albeit with an non-natural starting value of 0.

Cardinal: the number of elements needed to be jumped from the initial pointer to get to the memory location.

Perhaps they should be treated as Nominal numbers with added semantic constraints.

IMO: the use of "Zeroth" element should be banned. We should use 0-nth, 1-nth, 2-nth, 3-nth, ... (pronounced as zero-nth, one-nth, two-nth, three-nth...) if we want to refer to an element in an array with its index.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.