作者milonga332 ( U U)
看板Programming
标题[问题] 关於阵列从0或1开始算起的好处
时间Thu Aug 19 21:59:35 2010
http://www.iis.sinica.edu.tw/~scm/ncs/2009/07/go-to-considered-harmful/
上面这个连结虽然是讨论GOTO
不过Dijkstra大师在里面说
『我以为到了现在,一个专业程式员该有高一点的自我要求了,阵列应该从0算起,
我以为到了现在,一个专业程式员该知道自然数从 0 开始的好处了』
但是我在看Core Java的时候作者又说了
『Java counts the code units in strings in a peculiar fashion:
the first code unit in a string has position 0.
This convention originated in C,
where there was a technical reason for counting positions starting at 0.
That reason has long gone away and only the nuisance remains.
However, so many programmers are used to this convention that
the Java designers decided to keep it.』
如果可以抛开历史因素之类相容问题的话
那麽阵列索引到底是从0开始计算好,还是从1开始计算好呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.50.39.188
1F:→ loveme00835:想也当然是从0开始算起比较好啊, 因为140.121.197.115 08/19 22:09
2F:→ loveme00835:从0开始你可以依照实际应用决定要不要140.121.197.115 08/19 22:10
3F:→ loveme00835:空下第一个元素来方便计算存取, 从1开140.121.197.115 08/19 22:11
4F:→ loveme00835:始就不行140.121.197.115 08/19 22:11
5F:→ LPH66:我觉得单纯只是arr+i*size好做而已... 140.112.28.92 08/19 23:00
6F:→ yoco315:我觉得作者在胡扯.. LPH +1118.160.114.217 08/20 00:10
7F:→ yoco315:从0开始是有计算上的好处的,这点没有改变118.160.114.217 08/20 00:10
8F:→ loveme00835:如果是从java的角度来看, 转成b-code140.121.197.115 08/20 00:13
9F:→ loveme00835:时应该可以做点手脚, 这样应该不会太140.121.197.115 08/20 00:14
10F:→ loveme00835:难做吧?140.121.197.115 08/20 00:14
11F:→ loveme00835:以下面 l 大那篇来解释, 除了内建型态140.121.197.115 08/20 00:15
12F:→ loveme00835:自订类别都是阵列参考, 实作上不用一140.121.197.115 08/20 00:16
13F:→ loveme00835:定要map到最开始, 浪费一个参考的空间140.121.197.115 08/20 00:17
14F:→ loveme00835:应该不是大碍140.121.197.115 08/20 00:17
15F:→ MOONRAKER:我听大师的,Dijkstra +1 XD125.227.222.205 08/20 00:53
16F:→ MOONRAKER:keep it simple有时还是很重要125.227.222.205 08/20 00:54
18F:→ milonga332:楼上这篇讲的不错耶,很清楚 123.50.39.188 08/20 11:42
19F:→ ykjiang:这是品味问题,Java 那个品味差,所以没差 61.230.64.43 08/20 12:27