views:

283

answers:

8

In Java/C++, for example, do you casually say that 'a' is the first character of "abc", or the zeroth?

Do people say both and it's always going to be ambiguous, or is there an actual convention?


A quote from wikipedia on Zeroth article:

In computer science, array references also often start at 0, so computer programmers might use zeroth in situations where others might use first, and so forth.

This would seem support the hypothesis that it's always going to be ambiguous.


Thanks to Alexandros Gezerlis (see his answer below) for finding this quote, from How to Think Like a Computer Scientist: Learning with Python by Allen B. Downey, Jeffrey Elkner and Chris Meyers, chapter 7:

The first letter of "banana" is not a. Unless you are a computer scientist. For perverse reasons, computer scientists always start counting from zero. The 0th letter (zero-eth) of "banana" is b. The 1th letter (one-eth) is a, and the 2th (two-eth) letter is n.

This seems to suggest that we as computer scientists should reject the natural semantics of "first", "second", etc when dealing with 0-based indexing systems.

This quote suggests that perhaps there ARE official rulings for certain languages, so I've made this question [language-agnostic].

+23  A: 

It is the first character or element in the array, but it is at index zero.

Jason Coco
Very nicely put!
fastcodejava
+4  A: 

Probably subjective but I call it the first element or element zero. It is the first and, Isaac Asimov's laws of robotics aside, I'm not even confident that zeroth is a real word :-)

By definition, anything preceding the first becomes the first, and pushes everything else out by one.

paxdiablo
It is `[subjective]` until someone points to an authoritative recommendation that rules one way or the other. Then it becomes `[best-practices]`.
polygenelubricants
+6  A: 

To quote from this wikipedia article:

While the term "zeroth" is not itself ambiguous, it creates ambiguity for all subsequent elements of the sequence when lacking context, since they are called "first", "second", etc. in conflict with the normal everyday meanings of those words.

So I would say "first".

anon
Damn good point! Also, "zeroth" is awkward and sounds like a speech impediment.
Charles
+9  A: 

The term "first" has nothing to do with the absolute index of the array, but simply it's relative position as the lowest indexed element. Turbo Pascal, for example, allows arbitrary indexes in arrays (say from 5 to 15). The element located at array[5] would still be referred to as the first element.

Jason Nichols
Not **Turbo** Pascal, just Pascal :)
Alexander Pogrebnyak
+1  A: 

It depends of whether or not you are a fan of Isaac Asimov's robot series.

Judge Maygarden
+2  A: 

Definitely first, never heard zeroth until today!

denis
+2  A: 

I would agree with most answers here, which say first character which is at zero index, but just for the record, the following is from Allen Downey's book "Python for Software Design":

So b is the 0th letter (“zero-eth”) of 'banana', a is the 1th letter (“one-eth”), and n is the 2th (“two-eth”) letter.

Thus, he removes the ambiguity by either using:

a) a number and then "th", or b) a word and then "-eth".

Alexandros Gezerlis
+1 for the quote. Let's get more ruling one way or another from if not authoritative, at least credible sources.
polygenelubricants
+2  A: 

The C and C++ standards say "initial element" and "first element", meaning the same thing. If I remember to be unambiguous, I say "initial", "zeroth", or "first counting from zero". But normally I say "first". That banana stuff is either a humorous exaggeration or a bit bonkers (I suspect the former - it's just a way to explain 0-indexing). I don't think I know anyone who would actually say "first" to mean "index 1 of a 0-indexed array" unless they had first said "zeroth" in the same paragraph in order to make it clear what they mean.

Steve Jessop
Do note that the quote uses "one-th" and "1th" instead of "first" and "1st". I actually like this system; anything that moves toward mathematical precision and away from natural language ambiguities/irregularities is a good thing for me.
polygenelubricants
Sure, but I don't know anybody who says "one-th" either. I think they're just presenting it hypothetically, as a characterisation of what 0-based array indexing *would* be, if it was used as a set of ordinals in speech.
Steve Jessop
@ Steve Jessop -- Regarding the question of humorous exaggeration or it being hypothetical: perhaps. On the other hand, on a different page the author uses the same notation matter-of-factly, so this suggests that he considers it to be terminology (possibly of his own invention): "The operator [n:m] returns the part of the string from the 'n-eth' character to the 'm-eth' character, including the first but excluding the last.".
Alexandros Gezerlis
OK, defining terminology makes sense too. I'm surprised they present it as "to a computer scientist, the first letter of 'banana' is 'a'", since that's *not* the terminology they're defining, and it's also not true in my experience. "one-eth", "two-eth", "1th", "2th", "3th" don't show relevant Google hits.
Steve Jessop
Agreed (a.k.a. +1), though they're not defining the first letter of banana to be a, only the 1th letter. That's why I quoted from the next edition of the book (with only one author) which does not contain the "to a computer scientist" part.
Alexandros Gezerlis
Ah yes, your later version of the quote is more business-like, not mentioning "first" at all, just defining terms.
Steve Jessop
I just realized I was wrong: the later version also contains the discussion of computer scientists and first (but in a separate paragraph): "For most people, the first letter of 'banana' is b, not a. But for computer scientists, the index is an offset from the beginning of the string, and the offset of the first letter is zero."
Alexandros Gezerlis