当前位置:网站首页>Solid basic knowledge + correct method is the key to quickly read the source code

Solid basic knowledge + correct method is the key to quickly read the source code

2022-06-11 00:56:00 One Yu and one Yu

Last one We quickly reviewed the steps to read the source code , At the same time, it compares JUnit3 and JUnit4 Differences between .

This is 《 How to read the source code efficiently 》 Part 14 of the topic , It's also the last one , Make a summary of the topic .

First , The first article of the topic describes several incorrect ways to read the source code :

  • Read the source code without knowing the project

  • Read the latest version of the source code directly

  • Read the complete source code line by line

  • adopt debug The way to read the source code

The reason why these methods are wrong , It is determined by our memory : Our memories can be divided into 「 short-term memory 」 and 「 Long term memory 」! about 「 short-term memory 」 Come on , Generally, normal people can only remember 7( Addition and subtraction 2) About random information . The above four methods are actually irregular memory . But no item has a row count of 7 Right and left , So the above way to read the source code , It is difficult to read the source code of the project .

next , project Second articles Provides 15 Tips to improve the efficiency of reading source code :

  • Understand the purpose of the author's development project : Know the target , Just know the direction

  • First use it skillfully : Learn to walk first , Run again

  • Read the official documents : It is the author who knows the project best , Read the document well

  • First understand the concept : We are actually understanding the world through concepts

  • Understand the technical background of the version : Understand the technical limitations , Version iterations do not necessarily change requirements , Maybe it's just the technology itself

  • There is no need to read the latest version of the code : The new version has many functions , But the core functions have not changed

  • You don't need to read all the source code : Less is tens of thousands , You can read hundreds of thousands of lines of code ?

  • Read more than one version : Understand the differences between versions , Be able to better understand the project

  • Top down carding : First, sort out the overall process

  • Bottom up induction : Summary is very important

  • Subtract first , Add again : Find out the core model first , Based on the core model extension

  • Find the relationship from the interface : The interface is an external protocol , You can quickly locate the caller

  • Drawing assisted reading :90% The information comes from vision

  • Design pattern assisted reading : Understanding design patterns can speed up code understanding

  • debug Just to help :debug It is only used to verify whether the carding process is correct

this 15 The purpose of this tip , Is to build the impression and model of the target project .
Last , We sorted out the detailed steps to read the source code :

From the above process , You'll find that , We are actually :

  • Continue to model the source code

  • Then put the model into the process , Refine the process

Repeat these two steps , Refine and improve the process from the core module to the non core module , Finally, a complete project flow .

Reading source code is a process of active exploration , You need to constantly build your process model from the code . When you find yourself mechanically following the code StepIn、StepOver When , Have a cup of coffee 、 On a toilet 、 Take a rest , This will improve your efficiency in reading the source code .

meanwhile , The more solid your foundation is , The more efficient it is to read the source code , stay 「 Raise questions , Answer questions ! This is the right way to understand code design 」 In this article, you should deeply understand , Familiar with design patterns , Can quickly understand code design . Corresponding , If you have solid algorithmic knowledge , You can quickly understand the design of collections in the language ; If your IO Solid knowledge of concurrency , You can quickly understand Netty The design of the 、Redis Of IO Model .

Finally, I hope that the method of reading source code provided in this topic can help you finish reading the first open source project !

原网站

版权声明
本文为[One Yu and one Yu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206102337101589.html