There are several common phenomena in the technical workplace:
- You don’t need to read the source code for the technology you use in your job, you just need to be able to skillfully use it in the development process
- Look at the source too time-consuming, and easy to forget, if from the actual use of the process of problems, targeted reading source code, its learning efficiency will be more efficient, so usually do not need to see the source code.
I have a different interpretation of this, but let me explain.
This paper will be analyzed from the following four perspectives:
- The necessity of reading source code
- Source code Reading Tips
- Three states of source code reading
- Source code reading error
Warm tips: after the [code farmers turn over] number liu Xin under the guidance of big man, the second creation, in the face of boring source code encountered problems when insist on doing a more detailed interpretation, original link: excellent programmers essential skills how to read the source code efficiently (two more)
1. The necessity of reading the source code
1.1 General basic technology should be in-depth source code research
In the Field of JAVA, the author believes that common basic technologies include JAVA collection and JAVA concurrency (JUC). These are high-frequency techniques used in projects. Choosing the right data structure in the right scenario, choosing the right thread concurrency model, and controlling the lock granularity can significantly improve the availability and robustness of the application.
General technology is because of its universality, horizontal contrast is more representative, the discrimination of the workplace interview is very high, how to highlight themselves in the high sample is extremely necessary, through reading the source code, a deep understanding of its internal principle has become our magic weapon.
Of course, reading the source code is not the only way to know how it works, but as a famous programmer, face to face with the code, feel the charm of the code may be more direct.
1.2 Key areas should be in-depth source code research
In order to improve the recognition, we as professionals should create our own label, that is, ** “bright spot” **. Usually we should choose in daily work use of technology, in the use of accumulated rich experience, under the premise of online troubleshooting experience, should further study of its source, to master the technology into a system, thus the more mastery, early forecasting problem come from line, to avoid a large number of online fault, improve stability of power business authors efficiency.
For example, the author’s company adopts Dubbo and RocketMQ in microservices and messaging middleware respectively, and the author is fortunate to participate in the application, operation and maintenance of this technology stack, and has accumulated rich experience in using it. Therefore, in order to highlight the advantages in these two fields, the author reads the source code in detail. And published a column in the “Middleware Interest circle” public account and CSDN and other knowledge sharing platforms, because of systematic analysis was selected by the publishing house, invited to publish a book, RocketMQ Technology Inside came into being in this background, thus becoming a very bright label in the author’s professional skills, to help the workplace.
Source code reading is indeed very important, but must be systematic research, most people think that in dealing with the problem according to the specific problem to see the source code, will be more targeted, feel that there is no need to see the system.
There is no denying that this has its correct side, from the problem itself, look at the source faster efficiency, “input-output ratio” is higher, with more and more problems encountered, the understanding of the technology will be more and more deep, this is actually we usually speak of ** “experience” **. I think is desirable in most cases, this process is a passive process, and if the production due to no higher concurrent factors, may be one year, two years also won’t appear once or twice failure, this will cause the accumulation of experience will be very slow, so as to make the work of 4, 5 years friend its competitiveness important reason it is better to work two or three years, So my point of view is that if you want to create their own exclusive highlights, we still need to take the initiative to read the source code, into the system to master its design concept, implementation principle, to better create their own exclusive highlights.
2. How to read source code
Since reading the source code is essential, how do you read it? The author sorted out the following methodology based on years of source code reading experience:
- Understand the usage scenarios of this middleware and the responsibilities of the architectural design.
- Look for official documentation to understand the overall design philosophy of this middleware.
- Set up their own development and debugging environment, run the official Demo example, to lay a foundation for further research.
- First main flow and then branch flow, pay attention to cutting, break one by one.
- Read the source code with thinking and questioning.
After understanding its use scenario, combined with the official documents, try to understand the middleware needs to solve the problem, and think about how to solve, thinking process does not necessarily require us to come up with a specific answer, but in the real source code reading can be faster to understand its code meaning.
Of course, in the process of reading the source code may be to the problem, encounter unable to understand the author’s implementation intention, especially encounter some of their not familiar with the programming method (such as bit operation), there are usually two solutions:
- DEBUG allows you to understand your code in conjunction with runtime data.
- From easy to hard, try reading the source code of the JAVA Collections framework to refine your own source code research methodology.
Source code reading is actually the most difficult is not the code itself, nor can not understand its design concept, the most difficult is to adhere to, so here borrow the author’s motto and we encourage: the more efforts are lucky, only perseverance.
Source code reading three levels of realm
Next, I would like to combine the author’s four years of source code reading process, talk about some of my deeper understanding of source code reading, introduce the author in each stage of reading source code in the state.
- The early stages of the source code to read The old fans should be able to feel the author at the beginning of the source code to read the article, is basically a laundry list, the phenomenon is the most intuitive performance as a line of source code to add annotations, only focus on the underlying implementation details, but did not form a higher level cognitive, not yet refined and deep understanding of its design concept.
- Can ask questions, think, and refined with continuous sharing technical articles, the author got to know a lot of English, discovery, and Daniel, don’t speak any details at the beginning, but the design concept, this requests us in reading the source code to think more, and ask yourself if the need to realize how do we get started, how to design, with questions to research the source code, Through comparison and reflection, we can have a deeper understanding of the concept behind it.
- Thinking, questioning, and validation Which open source framework will actually whether there are bugs or implement is not reasonable place, if you can think when reading the source code and began to question its irrationality, and can be verified to prove their point of view, and then get in touch with the official, communication, building Isuue, jointly promote the development of the community, It shows that our ability and thinking have been greatly improved.
For this point, we can refer to the author’s questioning and thinking process of Sentinel corresponding circuit breaker implementation mechanism.
Current Limiting and Fusing from Sentinel Dubbo Adapter
4, source code reading errors
Source code reading is the means, but certainly not the end.
I found a lot of candidates in the interview process when it comes to a certain technology, first not to introduce the principle, but specific to a class at a draught, how the class is how to work, and so on, in fact this is not proper, source is the main reading purpose is a deep understanding of its design concept, working mechanism, facilitate our understanding of it system in the process of actual use. Strengthen its control ability, so as to avoid risks in advance.
Second source reading is very not recommended to come up directly DEBUG. If you start with DEBUG, it’s easy to get lost in the various branches of your code, lose perspective, and become clueless, which greatly increases the difficulty of understanding the source code and makes it easy to give up halfway.
Finally, learn a technology and be sure to go deep into the source code, especially non-mainstream, non-focus to create the field. For this kind of product, we usually only need to read official documents to understand its usage scenarios, what problems it can solve, understand its design concept and working mechanism, and flexibly use it to solve specific problems.
5, summary
Source code reading is not an end, just a means. For general basic technology such as JAVA collection, concurrency, need to focus on creating a bright spot in the field suggest we read the source code, into the system in-depth details to master its working mechanism, enhance its control ability, have the ability to avoid risks in advance.
Welcome to add the author micro signal (DINGwPMZ), pull you such as technical exchange plus group discussion, pay attention to the middleware interest circle, reply to the PDF can get massive learning e-books, help the workplace. \