在基于 0 的索引系统中,人们是否将索引 0 处的元素称为“第一个”元素?或“第零个”元素?

发布于 2024-08-27 18:48:58 字数 1133 浏览 4 评论 0原文

例如,在 Java/C++ 中,您是否会随意说 'a'"abc"第一个 字符,还是 >零

人们是否两者都说,而且总是模棱两可,还是有一个实际的惯例?


维基百科关于 Zeroth 文章的引用:

在计算机科学中,数组引用通常也从 0 开始,因此计算机程序员可能会在其他人可能首先使用的情况下使用零,依此类推。

这似乎支持了这样的假设:它总是模棱两可的。


感谢 Alexandros Gezerlis (请参阅下面的答案)以查找此引文,来自 Allen B. Downey、Jeffrey Elkner 的如何像计算机科学家一样思考:使用 Python 学习和 Chris Meyers,第 7 章

“banana”的第一个字母不是a。除非你是计算机科学家。由于不正当的原因,计算机科学家总是从零开始计数。 "banana" 的第 0 个字母(零 eth)是 b。第一个字母 (one-eth) 是 a,第二个字母 (two-eth) 是 n

这似乎表明我们作为计算机科学家在处理基于 0 的索引系统时应该拒绝“第一”、“第二”等自然语义。

这句话表明,也许对某些语言有官方裁决,所以我提出了这个问题[与语言无关]

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].

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

枯寂 2024-09-03 18:48:58

它是数组中的第一个字符或元素,但索引为零。

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

九局 2024-09-03 18:48:58

术语“第一个”与数组的绝对索引无关,而只是它作为最低索引元素的相对位置。例如,Turbo Pascal 允许数组中的任意索引(例如从 5 到 15)。位于 array[5] 的元素仍将被称为第一个元素。

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.

弱骨蛰伏 2024-09-03 18:48:58

引用这篇维基百科文章

虽然“zeroth”这个词本身并不是
模棱两可,它造成了模棱两可
的所有后续元素
缺乏上下文时的顺序,因为
他们被称为“第一”、“第二”、
等与正常相冲突的情况
这些词的日常含义。

所以我会说“第一”。

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".

茶底世界 2024-09-03 18:48:58

可能是主观的,但我称之为第一个元素或元素零。这是第一个,除了艾萨克·阿西莫夫的机器人定律之外,我什至不相信第零是一个真正的词:-)

根据定义,第一个之前的任何东西都会成为第一个,并将其他所有东西都推出一个。

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.

如果没结果 2024-09-03 18:48:58

绝对是第一,直到今天才听说过零!

Definitely first, never heard zeroth until today!

不再见 2024-09-03 18:48:58

我同意这里的大多数答案,其中第一个字符的索引为零,但仅供记录,以下内容来自 Allen Downey 的书“Python for Software Design”:

所以 b 是第 0 个字母(“zero-eth”)
'banana',a 是第 1 个字母
(“one-eth”),n 是第二个
(“two-eth”)字母。

因此,他通过使用以下方法消除了歧义:

a) 一个数字,然后是“th”,或者
b) 一个单词,然后是“-eth”。

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".

拥抱影子 2024-09-03 18:48:58

C和C++标准说“初始元素”和“第一个元素”,意思是一样的。如果我记得明确的话,我会说“初始”、“零”或“从零开始计数”。但通常我会说“首先”。那些香蕉的东西要么是幽默夸张,要么有点疯狂(我怀疑是前者——这只是解释 0 索引的一种方式)。我认为我不知道有谁会真正说“第一个”来表示“0 索引数组的索引 1”,除非他们在同一段落中首先说“第零个”以明确其含义。

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.

哭了丶谁疼 2024-09-03 18:48:58

这取决于您是否是艾萨克·阿西莫夫的机器人系列的粉丝。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文