How to learn the source code of an open source project

You have a task that needs to use an open source project; or the boss will explain one thing to you and let you understand something. How to start? How to start? My habit is like this:

  1. First of all, find and read the blog and information of the project. You can find the blog about a project in general through Google. A quick reading will give you a general understanding of the purpose, function, and basic use of the project.

  2. Read the project's documentation, focusing on documents like Getting started, Example, and learn how to download, install, and even use the knowledge required for the project.

  3. If the project provides a ready-made example project, first try to run the example according to the introduction of the start document. If it runs smoothly, congratulations on your successful start; if you encounter problems, first try to find the answer in the project’s FAQ and other documents , Again, you can search for problems (such as abnormal information) as keywords to find related solutions. If you encounter them, others will generally encounter them. Enthusiastic friends will record the resolution process; finally, you can submit the problem Go to the mailing list of the project , please help you to see it. Don't try to modify the example before running the example successfully.

  4. After running the first example, try to modify the example according to your understanding and needs, and test advanced functions.

  5. After understanding the basic usage, you need to start to understand the project in depth. Such as project configuration management, advanced features and best practices. Usually a well-functioning project will provide a user guide from shallow to deep. You don’t need to read this guide from beginning to end. According to time and interest, especially your own tasks, focus on reading some chapters and taking notes. .

  6. If time permits, try to build the project from source. Usually open source projects will provide a build guide to guide you how to set up an environment for development, debugging, and build. Try to build a version.

  7. If time permits and you are interested, you can try to read the source code:
    (1) Before reading the source code, check whether the project provides architecture and design documents. Reading these documents can understand the general design and structure of the project. When reading the source code, you will not be unable to start. .
    (2) Before reading the source code, you must be able to build and run the project to have an intuitive feeling .
    (3) The first step in reading the source code is to grasp the backbone and try to clarify the calling path of a normal code. This can be done by debugging to observe the variables and behaviors at runtime. Modifying the source code and adding logs and printing can help you understand the source code better.
    (4) Appropriate drawing to help you understand the source code. After clarifying the main body, you can draw the entire process as a flowchart or a standard UML diagram to help memorize and read the next step.
    (5) Select the "branch" code you are interested in to read . For example, if you are interested in network communication, read the code at the network layer and go into the implementation details, such as what library it uses, what design pattern it uses, and why Do wait. If possible, debug the detailed code .
    (6) When reading the source code, pay attention to the unit test and try to run the unit test. Basically a good unit test will clearly describe the function and boundary of the code.
    (7) After familiarizing with the source code, I found that there are areas for improvement, and I have the energy and willingness to put forward suggestions or issues for improvement to the developer of the project, and even help him repair and implement, and participate in the development of the project.

  8. Usually after reading the documentation and source code, you can have a more in-depth understanding of the project, but the field of the project, you may also want to search for related projects and materials to see if there are other better projects or solutions . A trade-off between breadth and depth.

The above are some of my personal habits, I did not follow this completely, but in this order, you can basically learn and use an open source project more efficiently.
Original link

Guess you like