看板 Programming 關於我們 聯絡資訊
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
loveme00835:想也當然是從0開始算起比較好啊, 因為140.121.197.115 08/19 22:09
loveme00835:從0開始你可以依照實際應用決定要不要140.121.197.115 08/19 22:10
loveme00835:空下第一個元素來方便計算存取, 從1開140.121.197.115 08/19 22:11
loveme00835:始就不行140.121.197.115 08/19 22:11
LPH66:我覺得單純只是arr+i*size好做而已... 140.112.28.92 08/19 23:00
yoco315:我覺得作者在胡扯.. LPH +1118.160.114.217 08/20 00:10
yoco315:從0開始是有計算上的好處的,這點沒有改變118.160.114.217 08/20 00:10
loveme00835:如果是從java的角度來看, 轉成b-code140.121.197.115 08/20 00:13
loveme00835:時應該可以做點手腳, 這樣應該不會太140.121.197.115 08/20 00:14
loveme00835:難做吧?140.121.197.115 08/20 00:14
loveme00835:以下面 l 大那篇來解釋, 除了內建型態140.121.197.115 08/20 00:15
loveme00835:自訂類別都是陣列參考, 實作上不用一140.121.197.115 08/20 00:16
loveme00835:定要map到最開始, 浪費一個參考的空間140.121.197.115 08/20 00:17
loveme00835:應該不是大礙140.121.197.115 08/20 00:17
MOONRAKER:我聽大師的,Dijkstra +1 XD125.227.222.205 08/20 00:53
MOONRAKER:keep it simple有時還是很重要125.227.222.205 08/20 00:54
Maisky:http://bit.ly/6HlLE9 71.59.112.4 08/20 08:01
milonga332:樓上這篇講的不錯耶,很清楚 123.50.39.188 08/20 11:42
ykjiang:這是品味問題,Java 那個品味差,所以沒差 61.230.64.43 08/20 12:27