what is Refactoring in software developement?

软件测试

In software engineering, “refactoring” source code means improving it without changing its overall results, and is sometimes informally referred to as “cleaning it up”. Refactoring neither fixes bugs nor adds new functionality, though it might precede either activity. Rather it improves the understandability of the code and changes its internal structure and design, and removes dead code, to make it easier to comprehend, more maintainable and amenable to change. Refactoring is usually motivated by the difficulty of adding new functionality to a program or fixing a bug in it.

In extreme programming and other agile methodologies, refactoring is an integral part of the software development cycle: developers first write tests, then write code to make the tests pass, and finally refactor the code to improve its internal consistency and clarity. Automatic unit testing helps to preserve correctness of the refactored code.

Code smells are a heuristic to indicate when to refactor, and what specific refactoring techniques to use.

The simplest example of a refactoring is to change an identifier (such as a variable name) into something more meaningful, such as from a single letter ‘i’ to ‘interestRate’. While the concept of renaming an identifier is relatively simple, the implementation of it may not be. Performing a global search-and-replace operation on any body of text can result in undesired results if by identifiers that contain the original identifier as a substring, overloaded identifiers and scoping rules. A more complex refactoring is to turn the code within a block into a subroutine. An even more complex refactoring is to replace a conditional statement with polymorphism.

While “cleaning up” code has happened for decades, the key insight in refactoring is to intentionally “clean up” code separately from adding new functionality, using a known catalogue of common useful refactoring methods, in conjunction with testing the code, to ensure that existing behavior is preserved. The new aspect is explicitly wanting to improve an existing design without altering its intent or behavior. Failure to perform refactoring can result in accumulating technical debt.

Some refactoring methods face challenges in being used.[1] Refactoring the business layer stored in a database schema is difficult or impossible, because of schema transformation and data migration that must occur while system may be under heavy use. Finally, refactoring that affects an interface can cause difficulties unless the programmer has access to all users of the interface. For example, a programmer changing the name of a method in an interface must either edit all references to the old name throughout the entire project or maintain a stub with the old method name. That stub would then call the new name of the method.

同类其他面试题 点击新一篇或旧一篇可浏览全部同类面试题

新一篇:
旧一篇:

共有1条 关于 “what is Refactoring in software developement?”的评论

  • 1
    Flagyl:

    There are certainly a couple more details to take into consideration, but thank you for sharing this information.

你有答案? 你对以上面试题有意见? 你想发表你的见解? 写下来吧!你的分享将会让很多人受益!

相关面试题

·常见的软件测试英语面试题
·缺陷BUG等级定义?都分为那些级别
·性能测试时要注意哪些东西?
·健壮性测试是什么?目的是什么?
·接口与路径测试都包括哪些内容?

版权声明:本站大部分内容为原创! 另有少部分内容整理于网络,如需转载本站内容或关切版权事宜请联系站长。未经允许,严禁复制转载本站内容,否则将追究法律责任。 本站欢迎与同类网站建立友情链接,请联系QQ:176687814