1244
說明:
|
← 2009-04-01 04:14:22 修訂第 5 版 ⇥
1246
converted to 1.6 markup
|
這個顏色代表刪除的 | 這個顏色代表增加的 |
行號 1: | 行號 1: |
舉例,計算 [http://en.wikipedia.org/wiki/Standard_deviation standard deviation] | 舉例,計算 [[http://en.wikipedia.org/wiki/Standard_deviation|standard deviation]] |
舉例,計算 standard deviation
還不如
假設之前沒看過 standard deviation 公式,雖然前面的 implementation 較簡短,但後面的方式,對於讀者而言,更容易理解。這也是為什麼 Sparse is better than dense 後面是接著 readability count 這一句,閱讀性必需擺在優先,除非該段程式碼有特別的 performance 需求。就算程式碼只有自己會看,但又如何保證自己回頭看時,不會忘了什麼是 standard_deviation ?把效能問題丟給 compiler 吧! 除非 compiler 無法產出可接受的效能。
另外,在 debug 時,如果公式的某一項出錯時,前面的寫法不容易 debug 。而後面的方式,因為每一項式都成獨立的一行,容易用 debugger 檢視,或者用 alert message 也很方便。