学习笔记之《Code Reading:The Open Source Perspective》Chapter one

来源:互联网 发布:网络女主播被粉丝砍死 编辑:程序博客网 时间:2024/05/17 00:56

Ø  Why to Read Code

Make it a habit to spend time reading high-quality code that others have written. Just as reading high-quality prose will enrich your vocabulary, trigger your imagination, and expand your mind, examining the innards of a well-designed software system will teach you new architectural patterns, data structures, coding methods, algorithms, style and documentation conventions, application programming interfaces (APIs), or even a new computer language. Reading high-quality code is also likely to raise your standards regarding the code you produce.

Ø  Signs of low quality code

l  An inconsistent coding style

l  A gratuitously complicated or unreadable structure

l  Obvious logical errors or omissions

l  Overuse of nonportable constructs

l  Lack of maintenance

Ø  Notice

Notice and appreciate the code's particular nonfunctional requirements that might give rise to a specific implementation style. Requirements for portability, time or space efficiency, readability, or even obfuscation can result in code with very peculiar characteristics.

Ø  How to read code

1.   Given a basic familiarity with programming and the underlying computer science concepts, you can in many cases use source code as a way to teach yourself the basics of the new environment.

2.   The next step involves actively changing the code to test your understanding. Again, begin with small changes and gradually increase their scope. Your active involvement with real code can quickly teach you the basics of the new environment.

3.   Once you think you have mastered them, consider investing some effort (and possibly some cash) to learn the environment in a more structured way. Read related books, documentation, or manual pages, or attend training courses; the two methods of learning complement each other.

Some tips:

1.   When you read code that falls in the above categories, keep in mind the specific nonfunctional requirements to see how your colleague satisfied them.

2.   If the code is valuable to you or your community, think about how you could improve it. This can involve using a better design or algorithm, documenting some code parts, adding functionality, or consider reinvesting your understanding of the code in improved documentation.

 

Andy编辑于2010-07-16   21:49:14