Bad taste of code

Source: Internet
Author: User
1. Reconstruction and core ideas

We have been emphasizing that we must constantly refactor the code in the program, but refactoring is indeed not easy as a high level of mental activity. Why is restructuring difficult to advance in a general team? I think there are two reasons: First, the project execution plan is not included. The team only wants to see the results faster, and there is no time for restructuring, programmers may have this awareness, but they have not joined performance, so they have not taken the initiative to restructure. Second, there is no uniform standard. Every specific developer will write the code implementation function according to the standard they think, resulting in inconsistent program code levels. I think these two reasons are the main reasons that impede refactoring.

Why is reconstruction required? From the perspective of long-term development of the project, restructuring can ensure that the project architecture is corrupted without frequent changes, ensure that functions can be implemented more flexibly and quickly in the next demand change without causing too many changes. We should follow the principle of "optimizing the internal structure without changing the function .".

2. Bad taste of code

Any dummies can write code that computers can understand. They can only write code that humans can easily understand. They are good programmers. So how do we refactor the code? To refactor the code, you must find an appropriate starting point and have a keen sense of smell of the Code. What is a keen sense of smell? The precondition is that we have a clear understanding of the six principles of the design model and are familiar with business needs.

We can discover the bad taste of the Code in terms of architecture and code. How can we find the bad taste of the architecture? In general, architecture design is the basic framework for building programs. At the architecture level, we need to divide the system functions, design data storage solutions, and design physical deployment, design the five aspects of the operating design and development architecture. If the program finds that the logic function of the existing system has exceeded the previously defined range during development, we will find a bad smell. If a three-tier architecture is originally required in the development architecture, but there is a two-tier architecture or direct access to the database in the development, it is not a bad taste that meets the specifications. On the other hand, from code writing, we should try to read the code as easily as possible. code writing should be tested using the six principles of design pattern. Bad taste of the project early discovery and early modification to keep the project within the expected scope of design.


3. reconstruction steps

Poor systems are difficult to modify, because it is difficult to find a change point. If it is difficult to find a change point, the programmer may make mistakes and introduce bugs. Restructuring has made the system that is already running poorly so that no one is willing to optimize the internal structure. If you have to refactor such a challenging system, using these steps can greatly reduce the introduction of new bugs in refactoring.

Every time I want to refactor, the first step is always the same. I have to create a reliable test environment for the code to be modified. Because we are all human beings, we need to treat ourselves as human beings, and we will inevitably make mistakes. Therefore, we need reliable testing (self-testing capability ).

After a complete test environment is created, we can optimize the internal structure of the Code step by step. Do not pursue code optimization that is successful step by step, keep small steps and fast, and constantly optimize the code.


Refactoring is a very tedious task. programmers must constantly improve their language capabilities so that the written code can be understood by others. We have a continuous awareness of refactoring and put it into practice to keep our code fresh, clean, and easy to read. Do not be a programmer like a fool or be a good programmer.


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.