[轉]想成爲出色的程序員,你必須承認你是個糟糕的程序員

 

Ted Neward在最近的博客裏引用了這個博客裏的有點“禪”味的句子,

To be a Great Programmer, you must admit that you are a Terrible Programmer
(想成爲出色的程序員,你必須承認你是個糟糕的程序員)

然後他說,

"I am human, therefore I make mistakes. If I make mistakes, then I cannot assume that I will write code that has no mistakes. If I cannot write code that has no mistakes, then I must assume that mistakes are rampant within the code. If mistakes are rampant within the code, then I must find them. But because I make mistakes, then I must also assume that I make mistakes trying to identify the mistakes in the code. Therefore, I will seek the best support I can find in helping me find the mistakes in my code."
(我是人,因此我犯錯。如果我犯錯,那麼我不能假定我寫的代碼不會有錯。如果我不能寫出沒有錯的代碼,那麼我必須假定代碼內錯誤橫行。如果代碼內錯誤橫行,那麼我必須找到它們。但因爲我犯錯,那麼我還必須假定在代碼內試着找錯時也會犯錯。因此,我必須尋求我所能找到的最好的支持,來幫我在我的代碼內找到錯誤。)

這樣的支持包括,
1. 使用一門靜態類型的語言 (編譯時和運行時的類型檢查等),使用靜態分析工具(Static Analysis Tool)
2. 大量使用斷言(assertion)
3. 瘋狂的測試(Testing Masochism--Masochism,根據在線字典,是受虐狂(“sexual pleasure obtained from receiving punishment (physical or psychological)”)的意思,即到了“以測試爲樂,以break one’s own code爲樂”的境地),追求測試涵蓋範圍至百分之百
4. 冷酷但誠實的代碼評審
5. 對可見系統當機(Visible Crash)的追求(即不隱藏錯誤/異常,讓錯誤/異常以導致當機的形式暴露出來)

鑑於多線程/併發代碼中的缺陷很難找,Ted Neward認爲業界裏流行的說法“dynamic-language-authored code can be proven correct by simple use of unit tests(用動態語言編寫的代碼使用單元測試即可證明其之正確性)”是有問題的,認爲我們需要各種形式的支持,我們需要更好的靜態分析工具,而不是完全拋棄它們。 

發佈了7 篇原創文章 · 獲贊 0 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章