What is refactoring and what is only modifying code?

后端 未结 10 927
Happy的楠姐
Happy的楠姐 2020-12-12 13:18

I know that refactoring is \"changing the structure of a program so that the functionality is not changed\". I was talking with some of the guys I\'m working with on my fina

10条回答
  •  暖寄归人
    2020-12-12 14:04

    http://en.wikipedia.org/wiki/Code_refactoring

    Code refactoring is the process of changing a computer program's internal structure without modifying its external functional behavior or existing functionality, in order to improve internal non-functional properties of the software, for example to improve code readability, to simplify code structure, to change code to adhere to a given programming paradigm, to improve maintainability, to improve performance, or to improve extensibility.

    I agree that refactoring code does include breaking existing code. Just make sure that you have unit tests so that you do not introduce any bugs, and the rest of the code compiles. Using refactoring tools like Resharper for C# makes this so easy!

    • Making code more understandable
    • Cleaning up code and making it tidier
    • Removing code! Redundant, unused code and comments should be deleted
    • Improving performance
    • Making something more generic. Start with the simplest thing possible, then refactor it out to make it easier to test / isolate or generic so it can work in different ways through polymorphism
    • Keeping code DRY - Don't repeat yourself, so a refactoring session might involve taking some repeated code and refactoring it into a single component / class / module.

提交回复
热议问题