会出错的程序员才是出色的程序员

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(用动态语言编写的代码使用单元测试即可证明其之正确性)”是有问题的,认为我们需要各种形式的支持,我们需要更好的静态分析工具,而不是完全抛弃它们。 

你可能感兴趣的:(多线程,单元测试,测试,语言,Crash,testing)