How should Java programmers learn the framework source code?

Pay attention, don’t get lost; continue to update Java related technologies and information! ! !

Preface

Insert picture description here
No matter what level of programmers, reading source code is a lot of benefits, especially for beginners, it can quickly absorb the essence of excellent framework code nutrition and grow rapidly. Unfortunately, the obscure source code can easily make people feel timid. Today I will share the method of reading source code.

Understand what problems the framework solves

This is not only helpful for reading the source code, but also for the whole study. Consider a question: The reason why you learned Vue\React, except that they are in full swing, you would be embarrassed to find a job if you don't study, and do you think that some of their excellent properties have brought me some benefits?

Developers need and should understand the trendy framework. Compared with the previous technical system, what problems the framework solves and where are the advantages. Learning with purpose will not be lost. For example, what is the biggest advantage of Vue\React? Componentization, learn with questions about how the framework solves this problem, and you will get twice the result with half the effort.

Understand the design ideas of the framework

We can't understand the source code (or seem to be struggling), not because we don't understand a certain grammar, but because we don't understand the author's ideas. Give a simple example:

 //这个方法可以获得point2顶角的弧度值
    functiongetAngle(point1, point2, point3){
    
    
       var bb = (point2.y - point1.y)*(point2.y - point1.y) + (point2.x - point1.x)*(point2.x - point1.x);
        var aa = (point3.y - point1.y)*(point3.y - point1.y) + (point3.x - point1.x)*(point3.x - point1.x);
       var cc = (point3.y - point2.y)*(point3.y - point2.y) + (point3.x - point2.x)*(point3.x - point2.x);
        var cosa = (bb + cc - aa)/(2*Math.sqrt(bb)*Math.sqrt(cc));
       return Math.acos(cosa);
    }

The getAngle method receives three coordinate parameters and can calculate the radian value of the vertex angle of point2. If you don't tell you that this uses the law of cosines of triangles, I am afraid you will not be able to see how it is calculated for a long time.

Ways to understand the design thinking of the framework :

  • Go to the official website of the framework to see the documentation. Open source framework, regardless of details, this is definitely the first-hand authoritative information
  • Go to the Internet to search for other people's analysis summary (source code analysis will not be less), in most cases, there will be a great god who has studied it, standing on the shoulders of giants can save a lot of things

In addition, the design idea is the entire framework level. For each implementation detail, many design patterns are used, such as functional programming (the most commonly used in Js), singleton mode, agent mode, factory mode, etc., which requires Usually accumulated. After a certain amount of code has been accumulated, it is recommended to read some design pattern books, which are beneficial to your own code design and reading the source code of others.

Build a debugging environment to find out the main context of execution

Subdivided into each module, it is necessary to have an overall grasp of the module function, how to achieve this "grasp"? In addition to official documents and online information, the best way is to write a simple demo, set up a good test environment, add some debugging information, and naturally clear the life cycle of the framework, which module needs to be called at each step (for the directory structure Very clear and excellent framework, sometimes you can guess intuitively, print the log to confirm)

Distinguish the priority

The source code of the framework is a lush, towering tree, and what you have to do is climb up from the root. The tree has so many branches and the time is so expensive. Reading strategies are very important. Our reading path should be based on the main process (that is, the main drive of the tree, so that we can reach the apex as quickly as possible), and for some small details, we will slowly nibble after this (or when necessary).

For example, if you want to read the source code of Vue, there is a directory for parsing templates, generating syntax tree AST, and finally generating Render Function. In fact, the most important step in this step is the result of this Render Function. How to parse the template and generate the syntax tree You can put it aside first, and then look back when you need it. Otherwise, you can easily get stuck at a certain point and you will have the idea of ​​giving up.

Persistence

With proper technical strategy, it is normal to encounter difficult and difficult problems. At this time, the test is perseverance. Continue to debug, search for information, or find a great god to ask questions, as long as you don't give up.

Learn to ask for help

No matter how strong your self-study ability is, whether you are P4 or P7, there will always be difficulties. Ordinary people who encounter bottlenecks can only silently attack again and again. If the impact is successful, it is another world; if the impact fails, it will be frustrated and lost for a while, and at worst, it will be devastated.

What if someone leads the way? Anyone who has read the novel knows that if someone guides you during the clearance, you can avoid a lot of detours if you learn from the experience of the predecessors. Life is only a few decades old, so why not save time to learn more and do more meaningful things.

In order to help you improve yourself as soon as possible and advance more efficiently, I have carefully prepared the framework source code series materials, hoping to help you break through yourself as soon as possible!

资料视频

Insert picture description here

电子书

Insert picture description herePlease poke me hard! Get it for free!

Guess you like

Origin blog.csdn.net/XingXing_Java/article/details/95617064