Code refactoring principles-important for later reference

Source: Internet
Author: User

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

    • Create a new method
      • New method
      • Copy the code you want to extract directly into the new method
      • Adjust parameters according to requirements
    • Adjust old code
      • Comment The original code, give yourself a chance to regret
      • Call New method
    • Test
    • Optimized 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
    • Test
    • Modify 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

Code refactoring principles-important for later reference

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.