Step 1 Code Refactoring

Source: Internet
Author: User

Code refactoring

Introduction to Code Refactoring

Refactoring purpose

    • The same code is best to appear only once
    • Primary and Secondary methods

Main method

Contains only sub-methods that implement complete logic

Clear thinking, easy to read

Secondary method

Implement specific logic functions

After the test passes, almost no maintenance is followed

Steps for Refactoring

1 Create a new method

? New method

? Copy the code you want to extract directly into the new method

? Adjust parameters according to requirements

2 adjusting Old Code

? Comment The original code, give yourself a chance to regret

? Call New method

3 Testing

4 optimization Code

? In the original position, because to take care of more logic, the code might be justified

? After extraction, because the code is small, you can check whether you can optimize

? Branching is more nested, not only performing poorly, but not easy to read

5 Testing

6 Modifying comments

? In development, the more comments are not the better

? If the comment is ignored, it may be some time before you can read the comment

? . m key implementation logic, or complex code, need to add comments, otherwise, long time you can not understand!

? All the properties and methods in. h need to have a full comment because the. h file is for the whole team to see

Refactoring must take small steps to change the test

Step 1 Code Refactoring

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.