How efficient learning and reading the source code?

I. Background

Java as a development engineer, want advanced, others read the source code of the project, especially the core open source technology stack excellent source of essential steps.

So what is the efficient way to read the source code it?

For example, buy some common "xxx-source analysis" books, but there is a problem, just started to see the time is very difficult to keep up, appeared to be very boring, and probably reading may still have no idea.

But also as a direct source pull down, I do not know how to start.

Today, friends and discuss this issue, we believe that the better reading skills and learn the source of finishing here.

Second, a good way

Pull source code, unit tests, debugging techniques, accessibility and understanding of IDE plug-ins of various call relationship.

According to unit test break point, view the call stack.

Binding interpretation of the source books and articles go to understand.

Combined with official documents and document functional architecture documentation to read.

As dubbo architecture diagram

There are a great help to grasp the whole source code and schematics, dubbo official documents and even supporting source code screenshots.

 

After the encounter with a problem or issue in-depth study of a piece, with a blog accumulated and sub-item.

 

Third, the specific method

2.1 github pulling See source + + Note source unit tests

To pull on github source code (source project proposal directly after pulling clone of the original project or fork).

We recommend fork source, so local can add your own comments to the source code.

 

After or shortcut keys to enter the source code, have the upper right corner IDEA "Download Source" pull source in the project, to facilitate debugging and learning.

Because the source code annotated , and most open source projects, in particular the comments of outstanding foreign open source projects are very detailed, including class action function and meaning of the parameters are very clear.

Also good open source projects are bound to have unit tests, unit tests almost every class has.

Want to focus on learning a class, you run a unit test, understand the purpose of the function, usage, etc. according to unit testing angle .

2.2 breakpoint debugging to see the call stack Dafa

Breakpoint debugging by stepping through the stack information, watch to see through the various classes of property.

There are a great help to understand the program flow and data changes.

debugging

Here is very important , because the conventional single-step debugging is to go down, but here stack by calling the bottom left corner to view the stack frame has been pushed onto the stack, the upper view function calls! ! !

Such as playing a part in the life cycle of spring as a breakpoint in the constructor, where it can be traced back to the early days of the calling code to initialize the bean.

But also realize the "Back" by removing the frame.

There are a great help to analyze source code! ! ! !

2.3 View class in the main function

mac shortcut cmd + f12

Double-function can jump to the corresponding source code.

2.4 View inheritance Dafa

By inheritance of a class can understand the "essence" is valid.

And by double-clicking, you can jump to the source code of any class inheritance relationships.

2.5 View call relationship

By "Call Hierarchy" view called relations

By right "find usages" View call

Double-click can go into the source code.

2.6 does not jump or a sub-function display parameters when you view the source code source

Shortcuts on the mac is cmd + y

This is of great help in the study of the source code, not only save a lot of time, but also better.

Can be used in the parameter can also be used in the subroutine.

 

 

2.7 dependency (dependency matrix, dependent on UML, etc.)

Dependency matrix

 

The basic explanation:

Green uses the gray class, class uses gray yellow class.

Red represents a cyclic dependency formed.

As shown in FIG we mouse on "BatchExecUtil", seen from the top right.

Green part BatchExecUtilTest use to BatchExecUtil.

BatchExecUtil used to turn the following four categories.

Can switch to a different class (row), see the relationship, the figure is switched to "SimpleRetryUtil" view:

 

Third, the use of IDEA shortcuts and various other auxiliary functions to improve efficiency

To learn and master the idea popular shortcut key here is not introduced one by one.

 

For example, click on the upper left corner of the package can switch to view, modify changes in the file, and so on.

Also can be more familiar with the other advanced features in the analyze menu bar

If you think this article has helped you, welcome thumbs comment, please pay attention to me, I will try to create more and better articles.

Welcome to another planet my knowledge, knowledge Planet ID: 15165241 can talk about.

https://t.zsxq.com/Z3bAiea   marked CSDN from the time of application.

 

 

-----------------------------------------------------

I see programmers CSDN 1024 event (October 24, 2019 deadline)

If I have a blog to help you, and there is time to welcome the browser which micro-channel scan code to help me support my point of praise:

 
Published 379 original articles · won praise 862 · Views 1.32 million +

Guess you like

Origin blog.csdn.net/w605283073/article/details/89290798