Source talk about reading

source code

When problems encountered in software development, I tend to solve problems without the need to read the source code, I will give priority to check the official documentation, FAQ, google or stackoverflow and other sites, there is no case to see their predecessors have encountered I had similar problems. Read the source to solve the problem, be killer. Of course, there is another demand, that is, want to know the details of design software by reading the source code, to achieve the purpose of learning, for example, by reading Dubbo source, I can understand the design details of a RPC framework.

premise

To do some preparation work before reading the source code.

First, make sure you master the basic knowledge related to, for example, if you want to read the Linux kernel source code, to grasp the basic concepts and principles C language syntax of the operating system, if you want to read the Spring source code, to grasp the Java language foundation, Maven use of design patterns and so on;

Second, we must learn to use the software or framework for understanding the use of this software scene or frame, what function, what similar competing products, or in the process of learning to use the software framework, the most important reference is the official document, a software quality models or frameworks, official documents generally include three: fast start, that some of the demo; reference document, the most detailed documentation, including the interpretation of the concept of property; FAQ: for users answers to frequently asked questions;

Third, a preliminary understanding of the overall organizational structure of the code, each folder is what to do with.

Debugging environment

Debugging environment is very important, with the debugging environment, you can break needed to read the source code is very helpful. As for how to build a debugging environment, different situations have different approaches, such as MAT source, I was first spun off its core logic and its own debugging unit tests; for Dubbo source code, I wrote it is a Dubbo service provider, a service consumer Dubbo, and was built up after the installation ZK; Spring for the most simple, using the Spring boot start a hello word in the demo can be.

Read the scene

After doing the above preparations, I will follow the function or scene to read the source code, for example, when reading the source code MAT (memory analysis tool), I was reading in accordance with the following steps: document analysis, index creation, query class histogram, dominant tree queries, view query thread and so on; at the Spring source code, I will follow the launch of the Spring container, the working process of IoC, AOP working process, the introduction of the static properties of other functions to read; in read Dubbo source, I will follow the service releases, service subscription, service call three main scenarios source code reading. By function or scene read, allows us to have an understanding of the code as a whole, then you can enter some details of their concerns, for example: in the MAT, the index file is how to create, in Dubbo, the request timeout mechanism and heartbeat mechanism is how to achieve.

to sum up

The process of reading the source code, I summarized some points to note:

  1. Read the top down, the first to grasp the whole, big process, and then cut to the corresponding branch as needed
  2. Omit some details such as checking the parameters, error handling, data format conversion and storage
  3. Try to be ready to debug environment
  4. To focus on the core business logic or algorithms
  5. Preferably some notes or documents can be output in the reading process, for example, the flowchart of FIG module division, a function of, for a business scenario, in the timing chart between several modules and the like, can first handwritten documents, and then forming an electronic version of the archive.

Above are some of my own experience of reading the source code for, if you have a good experience or ideas, please share with me in the comments area


This focus on the number of back-end technology, JVM troubleshooting and optimization, Java interview questions, personal growth and self-management, and other topics, providing front-line developers work and growth experience for the reader, you can expect to gain something here.Jwadu

Guess you like

Origin www.cnblogs.com/javaadu/p/11220259.html