Optimize code importance and code importance

Source: Internet
Author: User

Optimize code importance and code importance

This article is in the study of the summary, welcome to reprint but please note the Source: http://blog.csdn.net/pistolove/article/details/45131085


I have been working for nearly a year and have been engaged in software development for more than three years. I have also written a lot of code, but the overall quality of the Code is poor. On the one hand

Lack of programming experience, writing code cannot take into account the overall situation; on the other hand, it may be due to frequent changes in the demand design, leading to the completion of the Code

Structural instability. These affect the quality of Code directly or indirectly, and the quality of code will directly affect the performance of the product and the user body.

Verification. These will influence the user's liking and attention to the product. It is undeniable that codes with good quality are logically clear,

The code structure is also clear. Naturally, the length of classes and methods in the Code is relatively short. The short code remains longer (no programmer does not

Like short code ). In this way, there will be fewer problems with the product.


However, the majority of cases are as follows: developers focus only on whether the functions are implemented, but seldom on how to implement them.

Code form to implement the function. It may be because the project is busy, too late to consider, or the developer's ability is limited. Developers themselves do not even

Understand what the internal logic of the code looks like, so that the code is often large due to logic confusion. Obviously, we can assert that there are 10 such codes

There are problems. Once a problem occurs, developers need to spend a lot of time understanding the code logic. Because of the large amount of code, the modification process is invisible.

It will increase the amount of additional code. Even if a problem is modified, other problems may occur. Over time, classes and methods will become bloated

. The final cause of this problem is that developers cannot fully understand the logic of the code they write. In the "Practice of programmers: from small workers

There is one sentence in Expert Book: Do not write code that you cannot understand, it will only accelerate the decay of the system. It is necessary for programmers

Think and understand the code you have written.


What is code with high quality? Many people may think of more design patterns and as many high-level things as possible. However, in my opinion,

The Code does not have to use some design patterns to appear to be of high quality. For developers, I think the code logic is clear.

Is very important. The second is the code's conciseness. Shorter classes and methods are preferred, so that problems are easy to find out. Programmers can

Fully understand the code you have written, and conduct continuous optimization on it to form code with clear logic and a short amount of code. (Pure

Personal Understanding. Different opinions can be discussed)

For a function, if time permits during initial development, most programmers will take it seriously and try to write the code briefly;

Some programmers write code just to implement the function without thinking seriously, leading to logical confusion in implementation.

Yes, but dozens or even hundreds of rows are used. This is the so-called "heap code" development method. Coding for the purpose of implementing functions is not taken into consideration.

The quality of code. If you do not consider refactoring the Code, such code will bring a lot of potential risks to the system. In my personal opinion

When coding tasks, you feel good about yourself. However, after a period of time, you will find a lot of questions when looking at your own code as a whole.

Question. The two methods that can be merged are not merged. Some global variables do not need to be created. Some methods can be extracted as a public method.

More or less, leading to unstable code.


After a complete understanding of the code, the code is simply reconstructed to eliminate the full variables and some local variables. The extraction method is...

After this series of code migration, the original code is completely unrecognizable, but the logic is clearer and the amount of code is shorter. I want to go through this

Code optimization times, the function will become more stable than before. It turns out that my idea is correct, but there are still a lot of problems, but at this time,

If there are some problems, you can quickly locate them. Compared with the previous method that found bugs in a hundred lines of code and many local variables, do not

Less time.


After a while, I browsed the code I have already written, and found that the Code is not very good. Many places still need to be adjusted and modified. This

Next, I used the previous practice to reduce the number of global and local variables, reduce the code length in the method, and extract some methods...

Some columns are modified and moved, and the original code is greatly changed, but it is not completely unrecognizable. The logic is clearer than before, and you can fully understand what a part of code is doing, and why. I want to go through code optimization again, and the function will be more stable. It turns out that my

The idea is correct.


The above example is given to illustrate that it is necessary to continuously refactor and modify the code. The code is not developed.

In the future, just like a waste of water, we should not make it "flow" or "change". Instead, we should often review the code we have written, criticize and think about it, and organize and reconstruct it. Make it more perfect and improve its quality. However, most programmers do not review and judge the code on a regular basis, as well as organize and modify the code. I often do this before I understand refactoring. In general, after the development task is completed, you can beat your ass and leave. If there are any problems in the future, let's just do that. This is actually not a good practice. First, it is reflected in not being responsible for the code written by itself; second, it is reflected in no self-improvement. Finally, in the final analysis, it is still reflected in the word "lazy". I think it is working for the company. There is no need to work so hard. I just need to finish it myself. Besides, the company hasn't given a raise salary ...... these ideas are irrational to me. Working at work in the company, I learned technologies to pave the way for my future development. How can I say it has nothing to do with myself! Besides, every time you modify and optimize your own code, it is a process of improving your logic thinking ability. How can you be too lazy to get ahead!


I hope this article can be shared! Continuous efforts and progress! At the same time, I hope this article will help you!



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.