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 :
「HelloWorld Great use of : adopt demo, Build a black box model 」: We explained what a black box model is and how it works demo To build a black box model
「 How to read documents , Build a conceptual model ?」: We explained why we should read the documentation ; Where to read documents and how to read documents . At the same time, it expounds how to build a conceptual model , Finally, the black box model is verified and improved by the conceptual model
「 Focus on core modules , Read less 80% Of 「 It's useless 」 Code 」: We explained why to find the core module and how to locate the core module
「 The key to reading source code efficiently : Build the core abstract model 」: We explained what an abstract model is ; Why build abstract models , And how to build abstract models . Finally through JUnit4 Demonstrate how to build an abstract model
「 There is no need to debug, Quickly sort out the core process of the code through the abstract model 」: We demonstrated how to tease out core processes through abstract models
「 Through the integration of abstract model and conceptual model , Refine the overall process of the project 」: We explained why we wanted to draw ; How to draw the core flow chart ; And how to integrate abstract model and conceptual model
「 The power of the model : Model-based , Quickly sort out the source code 」: We explained how to determine the calling class ; And improve the project process by sorting out the calling classes .
「 Raise questions , Answer questions ! This is the right way to understand code design 」: By answering the previous questions , To understand the design of the code
「Spring How is it integrated JUnit Of ?JUnit Source code Association extended reading 」: We sort out TestRunner The implementation process and Spring How to integrate JUnit
「 Same project 、 Reading the source code between different versions 」: Through to JUnit3 The quick sorting of the source code has reviewed the previous reading steps , Also on JUnit3 and JUnit4 Compare .
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 !









