Read the source need to pay attention to what the problem, what good source download site

Source: Internet
Author: User

programmers in addition to develop to look at the official document reading habits also need to have their own learning and communication platform, recommend a few source download site, you can go to the above learning, good source is suitable for beginners to learn faster. read someone else's code. Being a developer is a common thing to do. One is to learn a new programming language by reading someone else's code is the best way to learn, and also to accumulate programming experience. The first half of this article is mainly seen on the internet before, get here to share with you.

Collect all materials that may be collected

The first thing to do when reading the code is to collect all the information related to the project. For example, you want to do a project after-sales service, then you have to understand what the project to do, then the research documents, summary design documents, detailed design documents, test documents, user manuals are the first to get your hands. If you are studying so as much as possible to collect information about your studies, such as the code of your Linux file system, it is best to find the Linux user manual, the method of file system design, and the description of the data structure. (This information can be found in the bookstore).

The type of material is divided into several types

1. Basic information.

For example, you read the Turbo C2 source code you need to have the Turbo C2 function manual, the use of professional books such as manuals, msc6.0 or Java, not only the function manual, but also the library function manual. This information is the basis of your information. In addition, you need to have some information about UML as a query manual is also a good choice

2. Professional information related to the program.

Each program is related to the relevant industry. For example, I read a code about meteorological analysis, because it used a complex data conversion formula, so I had to find their college textbooks to review the content of advanced mathematics.

3. Documentation of related projects

This part of the data is divided into two, a related industry information, such as you want to read a tax system code then there are some financial/tax system of professional information and the relevant laws and regulations of the country are essential. In addition to this project needs analysis reports, summary design reports, detailed design reports, manuals, test reports, and so on, to collect as much as possible for your future code reading is very important

Knowledge Preparation

Understand the basics, don't come up to read the code, play a good foundation can do more with less effect

Backup, construct a running environment

The first thing that comes after the code gets hands is to make a backup, preferably engraved on a CD, and it's hard to do a little bit of code when you're reading it, especially if you want to do some modification or enhanced maintenance. And once the changes can occur, the time to recover is a frequent occurrence, if you do not use the version control software very well, it is a minimum requirement to leave a backup first.

It's a good idea to build a running environment for yourself after you've done the backup, which can be cumbersome, but running code and non-running code will be a lot less difficult to read. So it's worthwhile to spend a little more time setting up an environment, and we read the code primarily to modify the problem or to do the porting operation. Code that cannot be run has limited usefulness in addition to some techniques that can be learned.

Find the place to start

Do everything you need to know where to start, and read the program is no exception. In the C language, the first to find the main () function, and then read by layer, the other programs, whether VB, Delphi must first find the program head, otherwise you are difficult to analyze the hierarchical relationship of the program clearly.

Level reading

When reading the code, do not stick to the end, it is often easy to trees trees, reading the code is a better way to have a bit like the breadth of a binary tree-first traversal. In the program body is generally relatively simple, the function of the call will be less, according to the function of the name and hierarchical relationship can generally determine the approximate purpose of each function, your understanding as an annotation written on the edge of these functions. Of course it's hard to write all the annotations right at once, and sometimes it may even be the result of your guesses, but it doesn't matter that the annotations are constantly revised in the reading process until you understand the code. In general, the method of reading by layer is to keep the understanding of your system in the right direction. Avoid a sudden plunge into the details of the problem. One of the issues to be aware of when reading at a hierarchical level is to separate the system's functions from the developers ' writing code. In C, C++,java, Delphi has its own system functions, do not read these system functions, unless you want to learn their programming methods, otherwise it will only waste your time. The system functions are expressed, annotated their role, there are several ways to differentiate between system functions and self-coding functions, one is the system function of the programming style is generally better, and the self-compiled function of the programming style is generally relatively poor. From the variable name, indentation between lines, annotations and other aspects can generally be distinguished out, the other is like Ms C6++ will be in your programming when you generate a lot of files out, there are many files you do not use, you can according to the file name to distinguish the time is a system function, and finally if you are not sure, Then use the development system of the Help system to check the function name, the parameters and so on to determine.

Write annotations

Writing annotations is one of the most important steps in reading code, where the source code we read is generally a system that we are unfamiliar with, and there are a few problems in reading people's codes.

1 It is not easy to understand the programming ideas of others, even when you know the idea of the program.

2 reading code when the code is generally relatively large, if not in time to write annotations will often result in reading clear behind the phenomenon of forgetting the front.

3 reading the code will inevitably appear to understand the error, if there is no timely write annotations difficult to timely find these errors.

4 Do not write annotations Sometimes you happen to be difficult to determine a function when you read it, what its function is, often repeated reading, understanding of the phenomenon.

Basic methods for writing annotations:

1 guess to write, just beginning to read a code, you can not immediately determine the function of all functions, it is advisable to use a guessing method to write annotations, according to the function of the name, position to write a general comment, of course, there will be errors, but your annotations are actually not only adjusted, until finally you understand the entire code.

2 according to the function to write, do not put the annotations written in grammar, do not see fopen to write open files, see Fread write data, such annotations are not useful, but should be written here to develop parameter configuration file (* * * *. DAT) read out the system initialization parameters ..... , this is a useful annotation.

3 in the use of write annotations Another problem to note is that the system automatically generated code and the user's own development of code, in general, there is no need to write the system automatically generated code. Like Delphi code, we often have to write some of our own code snippets, but also some of the system automatically generated code snippets, which are written in the reading process is to write annotations, but there are some non-modified automatically generated code there is no need to write annotations.

4 Write more detailed annotations in the main code section. There are functions or classes that play a key role in the program, so write more detailed annotations. This is a great help to understand your code.

5 It is difficult for you to understand the place to write detailed annotations, where there are often some programming skills. Don't understand how these programming skills will be problematic for your future understanding or transplant.

6 Write Chinese notes. If your English is good enough, do not look at this, but a lot of people in English is not very well, then write Chinese notes, we write annotations to speed up their understanding of the speed. Chinese is more suitable for Chinese than English in most times. It's better not to write a few English annotations that no one can read.

Repeat Reading

You can read all the code at once to understand that there is no one. At least I haven't met yet. Repeated reading of the same piece of code helps to understand the code. In general, when you first read the code you can skip a lot of pieces of code that you do not understand, write some simple annotations, in the subsequent repetition of the reading process, your understanding of the code is more profound than the previous understanding, so that you can modify the annotation errors in the place and the last one did not understand the other side. Generally speaking, the code reads 3, 4 times basically can understand the meaning and function of the code.

Run and modify the code

If your code is operational, it will improve your code speed by letting it run and reading the code in a single-step-tracking way. The code understands the meaning of the code by looking at the intermediate variables, and it can be of great help for future modifications.

Use your own code instead of the original code to see the effect, but keep the source code before

600 lines of a function, it is difficult to read, programming people are not a good habit. When reading this code, the code is modified to 14 functions. Each one is about 40-50 rows or so.

——————————————— Source Download website —————————————————————

I'd like to tell you a few of my favorite source download sites

CSDN (Chinese it community) it is a large comprehensive it portal that integrates news, forums, groups, blogs, documents, downloads, reading, tags, web pick, search,. NET, Java, games, video, talent, outsourcing, second bookstore, programmer, and many other projects in one. , but very practical inside there are many Daniel.

Devstore (source download) is mainly a developer service platform, bringing together a number of third-party developer services at home and abroad, providing developers with a one-stop solution from design and development to Operation promotion, source code and service evaluation is also a bright spot, very professional, very practical, the side gathered here are developers and PM, you can see.

Webmaster Home (website source code) for personal webmaster, Enterprise network Management to provide information and source code, including the language and types are also more.


Read the source need to pay attention to what the problem, what good source download site

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.