"Refactoring to improve existing code design" reading notes one

Source: Internet
Author: User
Two project experiences

At the end of 16, the maintenance of an old project was followed up, because the project was developed earlier and you know the various ways to do it. In the familiar with the code and in the follow-up to some specific tasks, often found that some code is not conducive to reading comprehension and add new features, if only one or two lines of code, I directly changed, but some longer code, because the time relationship is expected to be delivered as soon as possible, the decision and so on after the empty and then try again, the final result is

I recently followed an app project that used the Cordova-plugin-carmea plugin to capture and pick up pictures of your phone. When adding a new feature to the camera feature, I found that it was repeated in multiple places, and I had to search the entire project for the plug-in method to prevent omissions. Why refactoring existing code is not conducive to understanding and modification of why failed to promote the risk of refactoring, the code has been running 7, 8 years, a variety of data, testing environment is not, change the risk of too much interest, change the code to spend time, labor, but the department has not increased revenue Two interpretations of refactoring

Refactoring (noun): an adjustment to the internal structure of software to improve its understanding and reduce its cost of modification without changing the observable behavior of software

Refactoring (verb): Using a series of refactoring techniques to adjust the structure reconstruction of software without changing the observable behavior

Make the software easier to understand and modify the reconstructed HV lines

Do not change the observable behavior of software-- The premise of refactoring software function as usual after reconstruction

A robust testing mechanism is required to detect if our changes are causing bugs

As far as I am concerned, writing unit tests facilitates subsequent refactoring, otherwise there are always concerns that delay or fail to drive refactoring (but most companies are still driven by interest rather than quality-driven) to refactor objects

The smallest unit of refactoring is a common operation for code snippets that perform the same function

Extract method (Refining methods)
Move method when refactoring when adding new features when reviewing code when modifying errors
For me, the urge to refactor often occurs when new features are added, and, of course, the best thing to do is to refactor as long as the code needs refactoring.

Erase the dirt from the window so that you can see farther
I'm not a great program ape, I'm just a program with some good habits ape
Any fool can write a computer can understand the code, only to write human easy to understand the code, is a good program ape

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.