对于阅读别人的代码有何建议?
Joel : slow down...
Ramon Garcia Fernandez writes:
In your essay 'Things you should never do, Part I' you are against rewriting source code. But, what if the author of some source code is not available? What methods would you recommend to understand code written by another programmer? This situation is often encountered in the free software world, where you would rather reuse an existing program than write one from scratch, but it is difficult to read code written by another programmer.
My response:
I think the best way to read somebody else's code is just to SLOW DOWN... it's like deciphering a code, not like reading. Most people have trouble reading code because their eyes are used to reading at a certain speed from reading text written in human languages. But code is much more dense than English, and contains 'secrets' that need to be deciphered by looking elsewhere: for example, when you see that function call that says UpdateData(FALSE), unless you remember how UpdateData() works, you have to go look for it to figure out what the first argument is and what FALSE means.
It takes some skill to learn how to read code slowly and carefully, and many programmers are not patient enough (so they wind up rewriting the code from scratch). But you have to remember that it's still faster to read than to rewrite!
本文探讨了阅读他人代码的最佳方式,强调了耐心的重要性,并将其比作解密而非普通阅读。文章指出,理解代码中的‘秘密’需要放慢速度仔细研究,这与阅读自然语言材料完全不同。
51

被折叠的 条评论
为什么被折叠?



