How to Read System Source Code Efficiently

1. Find relevant information, documents, or search online to understand the implementation principle and code ideas of this system. (Look online to find the implementation principle of the framework)

2. Supplement basic knowledge. Through the study of relevant materials, you can know which technologies are used in the project code, which programming languages ​​are used, which algorithms are used, and so on. As the saying goes, "Sharpening a knife does not make a mistake in chopping wood". At this time, you need to learn the relevant technical foundations in order to achieve multiplier effect with half the effort. For example, if your project is implemented in go language, you need to learn the basic knowledge of go language, so that you can understand its principles better and faster when reading the project code. At the same time, for projects with running requirements, it is necessary to learn and build the running environment and compilation environment. (build project)

3. Start reading the project code. First find the main entry of the program. For example, most languages ​​will have a main function. You can start reading from the main function. Read the general structure of the code first, without having to investigate the details of each line of code. This way you can get an intuitive impression of the connections within the entire project code. After having a global view, compare the technical points mentioned in the documentation for step-by-step confirmation, find the correspondence between the principles explained in the documentation and the code, then understand it, and annotate and mark the lines of code. Finally, savor the entire project code. (Find the place where the principle and code correspond to the implementation)

4. Compile and run your project. Some incomprehensible or incomprehensible code when reading the code can be confirmed when running the project code. You can use gdb to debug a program, see how the program behaves under different conditions, and then understand it against the lines of code. I believe that at this point, you can master more than 70% of the code principles. (debugging code that doesn't understand places)

Fourth, read the project code repeatedly. Every read of the code yields something different. Many parts of the code have not been understood before, and the second and third reading will bring joy to another village. In fact, when reading the code for the first time, everyone will have a feeling that they can't understand it, and there will be an uncomfortable feeling. At this time, you have to endure it and continue to look down. After you read it 2-3 times, you can grasp the principle of this project. (repeat reading)

 

Reference: https://zhuanlan.zhihu.com/p/25739119

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326369675&siteId=291194637
Recommended