[转]想成为出色的程序员,你必须承认你是个糟糕的程序员

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值