Refactoring again in-depth understanding

xiaoxiao2021-03-06  41

Why is it necessary to reconstruct the "Reconstruction-Improved Design of Martin Fowler" One of the best-selling computer books for two consecutive years, you can know the extent to which the rejuvenation to the programmer . So what is the reconstruction? Reconstruction is based on the existing function of the software, improves software quality, performance, making its program's design mode and architecture more reasonable, improve software scalability and maintenance. Maybe someone will ask, why not spend more time when the project starts, but take time to refactively in the future? To know a perfect design, you can predict that any changes in the future, or a flexible design does not exist. The system designer is often only controlled from the big direction, but cannot know that each sub-branch season will never change, and users who make demand often have to start "product head argument" after the software is formed. After all, the system designer is not the first fairy, and the changes in function have resulted in the adjustment of the design. Therefore, "Test is the first, continuous reconstruction" as a good development habit, is increasingly adopted, tested and refactored to the Yellow River, and become a magic weapon to ensure software quality. By reconstructing the following goals: • Continuously biasing and improved software design reconstruction and design are complementary, it is complementary to each other. With a refactor, you still have to do pre-design, but don't have to be the best design, just a reasonable solution is enough. If you don't have a refactor, the programming will gradually corrupt the deterioration, and it is more like a line. Kite, uncontrolled wild horse. Reconstructing is actually the finishing code, let all code with divergent tendencies return to this border. · Make the code easier to understand that Martin Flower has a classic words in "Reconstruction": "Any fool can write a computer that the computer can understand, only the procedure written by human is easy to understand is an excellent programmer." In this regard, the author feels deep, some programmers can always write the running code, but the names in the code have dizzy to grasp the seat armrests, trying to pick up such code to pick up such a code. Will you want to escape? The software life cycle often requires multiple appraisers to maintain, and we tend to ignore these later people. In order to make the code are easily understood by others, you need to do many additional events when implementing software functions, such as clear typography layouts, concise annotations, which are also an important aspect. A good approach is to use metaphor named, namely the function of the functionality, named visualization or manicing techniques, a good attitude is to name each code element like a newborn, maybe the author is a bit Name parallelism, if you can Rong Xiang Ya, will be deeply available. For those names that make people feel confused and even misleading, they need fruits, and the big knife is in the shape of the big, never want to be in hand! · Help discovering hidden code defects Confucius said: warmth is known. Forced you to deepen your understanding of the code you wrote. After the author often wrote the program, the author happened to have a scene of the logic of his own program, and he was a thriller, and later found that this symptom is actually a "cold" commonly commonly commonplace. When you also happen, you can deepen the understanding of the original design by refactoring code, discovers problems and hidden dangers, and build better code. · From the long run, it will help improve programming efficiency. When you find a problem, it is often caused by the problem itself, but you use the wrong way, poor design tends to cause bloated codes. Improve design, improve readability, and reduce defects are in order to steadily.

A good design is half of success and stops by reconstructing improvement, perhaps in the current slowing speed, but it is not underestimated. When did the new official's first three fires, start a new project, programmers often ignite three fires: intensive, foot does not stop, work overtime, a lot of thousands of troops "Wrap the programmer's passion and the hitting of the keyboard struggle forward, like a broken bamboo, the attacking, directly refers to" Huanglongfu ". The development manager is the commander of this Haohao Tang Dynasty code team. He is responsible for the fate of this team. When Zhiheng officially saw the team of Juan Zhong training, he sighed, "I have such a military Where is it afraid of no victory? ". But unfortunately, this team in your hands is just a soldier, and the horse is in advance, and it is constantly growing, so the team is deformable. When the development manager discovered the team's deformation, it may be the temptation to hold the front of the mountain, stopping the steps to rectify the team. Kent Beck proposes the "code bad taste" statement, and the "team deformation" we propose is the same meaning, what is the signal of the team deformation? The code symptoms below is the strong signal of "Team Deformation": · There is a repetitive code in the code China has 118 vehicle production enterprises, the number is almost equal to the beauty, Japan, the number of car manufacturers, but the year of the country Yield is not as good as a foreign large car company. Repeated construction will only lead to efficiency and waste of resources. The program code is even more duplicated. If there is the same code block in the same class, please extract it into a separate method, if you have the same code in different classes, please refine it into a new class, forever Do not repeat the code. · Excessive classes and too long methods are often the abstract unreasonable results, and the abstraction is unreasonable will reduce the complex rate of the code. Method is the princes in the kingdom, the princes are too big to shake the central call. Due to too long is too complicated, the error machine rate is rising straight, while readability is straight, and the robustness of the class is very easy to break. When you see a too long, you need to find a way to divide it into multiple small methods for franchise. · Making a hair and need to move the whole body Modification When you find a small feature, or add a small function, it will trigger a code earthquake, perhaps your design is not ideal, the function code is too dispersed. · There is too many communication between classes A class that needs to call the excessive method of catenamics to access B's internal data. These two classes seem to be a bit about the relationship. Maybe these two classes should be together, and should not be divided Home. · Excessive coupled information chain "The computer is such a science, it is believed that any problem can be solved by adding an intermediate layer, so it is often more appended to the program. If you see a message you need to get in the code, you need a class method to call another class, layer mount, is connected as the oil pipe is as follows. This is often because there is too much adapter layer, and you need to see if there is a removable intermediate layer, or whether a more direct call method can be provided. · Each mountain's dry revolution If you find two classes or two methods, although there are different or the same features, you will find that it is often because the development team members are not caused. The author has written a very good string processing class, but because there is no timely announcement team other personnel, there are three string processing classes in the project. Revolutionary resources are precious, we should not have a romance of the mountains.

转载请注明原文地址:https://www.9cbs.com/read-52657.html

New Post(0)