Read Source Code Summary

Source: Internet
Author: User

Main processes and methods:


Step0. understand the overall design and concept of the system. 
An excellent system usually has an elegant overall design, which is connected by a set of concise concepts. It is best to first understand the overall framework and concepts of the system, which will provide a general guiding role for understanding the structure and operation of the system.

Step 1. Familiarize yourself with the project code structure


A good open-source project usually has a clear and hierarchical project structure.

The first thing to do is to get the project source code: to get an overview of the project's organizational structure, to find out which main modules (packages) and the main functions of each module (Package); each module (Package) what are the main classes and their functions.
Good project code usually has a good abstraction for every point involved in the system. Even if it is just a simple color string, we will try our best to use enumeration to implement it.

Step 2. Set the target and narrow down the scope

Before you start to read the source code, set a goal to drive reading. For example, you need to explore the problem that the proxools connection pool sometimes cannot obtain the database connection, or find out the internal implementation of the extjs paging control pagingbar. First, take a small branch, and narrow down the reading scope to a level that is easy to complete. The physicist was not able to understand the whole universe at once.
Step 3: Start with external Behaviors
Read the API documentation repeatedly, understand its external behavior, clarify the design's target requirements, and understand how these classes or modules collaborate to accomplish the overall goal. Read (if any) or draw a collaboration design diagram. In addition, based on your own development experience and talents,
Proactive thinking and bold guesses: how can we achieve it if we are ourselves? How can this problem be achieved? Step 4. Lock main and core classes and Methods

Any design involves an implicit or explicit division of work between "key roles" and "supporting roles. Reading the source code is not a blind and aimless behavior. Instead, you must first lock the main and core classes and methods as the starting point.Step 5: Mark the main process and draw a collaborative interaction Diagram
Skipping various details focuses on figuring out the main process, including the modules, classes, and methods involved, marking and drawing collaborative interaction diagrams.Step 6: break down the details
In pursuit of flexibility and scalability, the development framework is more difficult to understand than the business system code. In particular, the details are rooted in the wrong section and are mutually dependent. It doesn't matter. Multiple details are broken down into multiple small tasks.

 

Auxiliary Means: 

1. Reading and commenting

Make some necessary comments on the places you have read, mainly highlighting their usage and necessary implementation details;

2. Build the environment, run and debug

Set up the source code environment, run it, set breakpoint debugging, observe the results, and make a good tracking method;

3. Start from a simple perspective and be good at breaking down small tasks

Why can't I start with the source code of spring and tomcat? From JDK and JUnit, do you understand extjs grid code? Start with label and ComboBox; what is the difficulty for a huge class? It may be broken down into multiple small tasks.

Just like any skill, the skills for reading Source Code also need to be trained from the base of 1.1 points until they are skillful and proficient.

4. Find other things to do

Reading source code is not the best thing in the world. If it doesn't work well at first, you can read several functions and then do other things, such as activity activities, listening to songs, watching videos, and then come back to read them, to gradually enhance patience and adaptability.

Psychological test:

What is hard to understand is the opportunity for challenges and improvement.

There will always be something you can't understand or think about. In this case, you may need to make up for the basic knowledge, or learn some advanced skills. You must never miss this learning opportunity.

Patience and perseverance

This is a must-have and a must-have city. It is difficult and requires a lot of patience and perseverance. However, once attacked, it will lay a good foundation for the future.

References: 1. How to read others' source code 2. How to read source code 3. How to understand source code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.