PHP code maintenance, refactoring difficult to 4 reasons analysis _php Skills

Source: Internet
Author: User

This paper analyzes 4 reasons for the difficulty in the maintenance and reconfiguration of PHP code. Share to everyone for your reference, specific as follows:

Code maintenance, refactoring is a very unpleasant thing. In the following situations, it can be difficult to maintain and refactor code.

1. At the beginning of the project, we set some code norms, under a certain standard for development, but people's thinking is not the same, that is, each function of different people to achieve the logic may be so different, resulting in some people do not want to look at other people code, to change the code, The first thing to understand is what the person was thinking and how his logic was. So a lot of people think that there is the time to see other people's code, I will do it again. This idea does not have, see other people's code can also learn a lot of things. If you think so, I think the redundant code will be more and more, later refactoring will become more and more difficult.

2. The general procedures for job-hopping are more frequent, the beginning of the project, is 5 people (the founder of the project) development, and other projects on the line, may be someone left. There is not enough manpower for the company to recruit. What about the founder of the project, for new people, not too trusting, afraid to modify the original code will lead to the function of the online problem, so it is the best not to modify the online program, if the demand changes, it is best to rewrite class or function, so that the code will become more and more. Several classes may appear to be similar, or multiple function functions are similar.

3. Database redundant fields, too many redundant tables, it will make code maintenance very difficult. Because of functional optimization, or new requirements, the existing table structure does not meet the new requirements, this time, will go to the table to add a field, or hook up with another, the long-term past, the database has become very bloated, a large database, the code must not say, the program is around the data, redundant fields, redundant table to maintain, Otherwise the data will not be unified. The necessary redundancy can reduce the database query, if too much, only things will be returned. Therefore, when you modify the database, you should consider clearly, consider the future of the database and code to be refactored.

4. Personal reasons are the most important reason, first of all, to have the idea of chunking, can also be said to be oop thought, this idea is in the actual combat, this is to be a certain time. Do not ignore the overall consideration in order to realize the function in a hurry. If there is a new need, I will first consider how to achieve this demand, with the idea, I will not rush to develop this function, I will also consider this function module, will not be used in other places? If other places are used, how to make it more convenient for other places to use. I'm going to make so call this function module where the interface has only one. Then I will start to develop. There is also a point, do not believe that the requirements will not change, will not. A lot of people's ideas, the development of code, this point should also be taken into account, so the unified interface in the change in demand, I just modify a place, other places can be changed. If this is considered, early development, time will be a little more, but later maintenance is much faster.

A summary, with the above 4 points, refactoring the database, refactoring code will be inevitable

1. The human mind cannot be the same, everyone is trying to think in one place, but there is always such a difference.
2. Eager to complete the function, but not in-depth understanding of other people's code. It is not good to study others ' code as quickly as to develop it again.
3. Database redundancy, this I personally feel inevitable will appear, a project bigger, do strong, must be in constant growth, growth process, the database can not be immutable.
4. Lack of chunking thought, I think a project, is a lot of independent small pieces through a certain line of string up, code refactoring is to put these small pieces of the regroup, of course, each small pieces, in the refactoring before and after the implementation of the function will be different, but it is still in order to achieve a certain function, but only from the old to new.

The above points are I actually encountered in the development project process, welcome everyone to add.

For more information about PHP interested readers can view the site topics: "Introduction to PHP Basic Grammar", "PHP object-oriented Programming Program Introduction" and "PHP Excellent Development Framework Summary"

I hope this article will help you with the PHP program design.

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.