Why numbering should start at zero
为什么编号应该从 0 开始
To denote the subsequence of natural numbers 2, 3, ..., 12 without the pernicious three dots, four conventions are open to us
为了表示自然数 2、3、...、12 的子序列,没有有害的三个点,有四种约定向我们开放
a) | 2 ≤ i < 13 | |
---|---|---|
b) | 1 < i ≤ 12 | |
c) | 2 ≤ i ≤ 12 | |
d) | 1 < i < 13 |
Are there reasons to prefer one convention to the other? Yes, there are. The observation that conventions a) and b) have the advantage that the difference between the bounds as mentioned equals the length of the subsequence is valid. So is the observation that, as a consequence, in either convention two subsequences are adjacent means that the upper bound of the one equals the lower bound of the other. Valid as these observations are, they don't enable us to choose between a) and b); so let us start afresh.
有没有理由更喜欢一种惯例而不是另一种惯例?是的,有。约定 a) 和 b) 的观察结果的优点是,如前所述边界之间的差异等于子序列的长度是有效的。因此,在任一约定中,两个子序列相邻意味着一个子序列的上限等于另一个子序列的下限。尽管这些观察是有效的,但它们并不能让我们在 a) 和 b) 之间进行选择所以让我们重新开始。
There is a smallest natural number. Exclusion of the lower bound —as in b) and d)— forces for a subsequence starting at the smallest natural number the lower bound as mentioned into the realm of the unnatural numbers. That is ugly, so for the lower bound we prefer the ≤ as in a) and c). Consider now the subsequences starting at the smallest natural number: inclusion of the upper bound would then force the latter to be unnatural by the time the sequence has shrunk to the empty one. That is ugly, so for the upper bound we prefer < as in a) and d). We conclude that convention a) is to be preferred.
有一个最小的自然数。排除下限 — 如 b) 和 d) 中 — 强制从最小自然数开始的子序列,如前所述进入非自然数的下限。这很丑陋,所以对于下限,我们更喜欢 ≤如 a) 和 c)。现在考虑从最小的自然数开始的子序列:包含上限将迫使后者在序列缩小到空值时变得不自然。这很丑陋,所以对于上限,我们更喜欢 <,如 a) 和 d)。我们得出的结论是,约定 a) 是首选。
Remark The programming language Mesa, developed at Xerox PARC, has special notations for intervals of integers in all four conventions. Extensive experience with Mesa has shown that the use of the other three conventions has been a constant source of clumsiness and mistakes, and on account of that experience Mesa programmers are now strongly advised not to use the latter three available features. I mention this experimental evidence —for what it is worth— because some people feel uncomfortable with conclusions that have not been confirmed in practice. (End of Remark.)
备注 在 Xerox PARC 开发的编程语言 Mesa 在所有四种约定中都有整数间隔的特殊表示法。Mesa 的丰富经验表明,使用其他三种约定一直是笨拙和错误的根源,根据这些经验,现在强烈建议 Mesa 程序员不要使用后三种可用功能。我提到这个实验证据——就其价值而言——因为有些人对尚未在实践中证实的结论感到不舒服。(评论结束。
When dealing with a sequence of length N, the elements of which we wish to distinguish by subscript, the next vexing question is what subscript value to assign to its starting element. Adhering to convention a) yields, when starting with subscript 1, the subscript range 1 ≤ i < N+1; starting with 0, however, gives the nicer range 0 ≤ i < N. So let us let our ordinals start at zero: an element's ordinal (subscript) equals the number of elements preceding it in the sequence. And the moral of the story is that we had better regard —after all those centuries!— zero as a most natural number.
在处理长度为 N 的序列时,我们希望通过下标来区分其元素,下一个令人烦恼的问题是将哪个下标值分配给其起始元素。按照约定 a) 当从下标 1 开始时,下标范围 1 ≤ i < N+1;但是,从 0 开始,≤ i < N 给出更好的范围。因此,让我们让我们的序数从 0 开始:元素的序数(下标)等于序列中它前面的元素数。这个故事的寓意是,在这么多世纪之后,我们最好把零看作一个最自然的数字。
Remark Many programming languages have been designed without due attention to this detail. In FORTRAN subscripts always start at 1; in ALGOL 60 and in PASCAL, convention c) has been adopted; the more recent SASL has fallen back on the FORTRAN convention: a sequence in SASL is at the same time a function on the positive integers. Pity! (End of Remark.)
备注 许多编程语言的设计都没有适当地关注这些细节。在 FORTRAN 中,下标总是从 1 开始;在 ALGOL 60 和 PASCAL 中,公约 c) 已被采纳;最近的 SASL 又回到了 FORTRAN 约定:SASL 中的序列同时是正整数上的函数。可惜!(评论结束。
The above has been triggered by a recent incident, when, in an emotional outburst, one of my mathematical colleagues at the University —not a computing scientist— accused a number of younger computing scientists of "pedantry" because —as they do by habit— they started numbering at zero. He took consciously adopting the most sensible convention as a provocation. (Also the "End of ..." convention is viewed of as provocative; but the convention is useful: I know of a student who almost failed at an examination by the tacit assumption that the questions ended at the bottom of the first page.) I think Antony Jay is right when he states: "In corporate religions as in others, the heretic must be cast out not because of the probability that he is wrong but because of the possibility that he is right."
上述情况是由最近的一个事件引发的,当时我在大学的一位数学同事(不是计算科学家)情绪激动地指责一些年轻的计算科学家“迂腐”,因为——正如他们习惯的那样——他们开始从零开始编号。他把有意识地采用最明智的惯例当作一种挑衅。(还有“End of ...”惯例被视为挑衅;但这个惯例是有用的:我知道一个学生在一次考试中差点不及格,因为他默认了问题在第一页的底部结束。我认为安东尼·杰伊(Antony Jay)说得对:“在集体宗教中,就像在其他人中一样,异端必须被驱逐,不是因为他可能是错的,而是因为他可能是对的。
发表评论