重构.NET代码
我不知道重构是什么。如何使用以及何时使用?使用 VS2005 IDE 重构代码可以带来哪些好处?请解释一下。谢谢。
I don't know what Refactoring is. How it is used and when it is used? How one could benefit from Refactoring the code using VS2005 IDE? Please explain. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
重构是修改代码以增强其可维护性而不改变其行为的做法。
例如,您可以将变量从“x”重命名为“employeeCount”,以便该变量所指的内容一目了然。
或者,您可以重构一个方法,使其名称更接近其功能(“GetEmployeeById”而不是“Foo”)。
或者,您可以将一个非常大的方法分解为几个较小的方法。
重构的关键是您所做的更改不应影响代码的行为方式。如果是这样,那么你已经吃了一些东西。
有关更多信息,请访问http://refactoring.com
Refactoring is the practice of modifying code to enhance its maintainability without changing its behavior.
For example, you might rename a variable from "x" to "employeeCount" so that it's obvious what the variable refers to.
Or, you might refactor a method so that its name more closely resembles what it does ("GetEmployeeById" instead of "Foo").
Or, you might break a very large method down into several smaller ones.
The key thing about refactoring is that the changes you make should not affect the way the code behaves. If it does, you've borked something.
For more information, visit http://refactoring.com
重构只不过是在不改变代码功能的情况下重新编写代码。
这通常意味着重命名变量以使它们更有意义、重新组织源代码、将大型方法分解为较小的方法以及其他(内部)更改。
这简化了代码,使其更易于理解和测试。如果做得正确,最终的结果是“更好”的代码,更容易维护和理解。
Visual Studio 提供了一些工具来简化此操作 - 但您可以自由地使用或不使用它们。
Refactoring is nothing but reworking code without changing what it does.
This typically means renaming variables so they make more sense, re-organizing the source, breaking large methods into smaller ones, and other (internal) changes.
This simplifies the code, makes it easier to understand and test. The end result, if done properly, is "better" code that's easier to maintain and understand.
Visual Studio provides tools to make this easier - but you are free to use them or not.
请参阅代码重构:
Please see Code refactoring:
重构是将代码安排为更好的设计,而不改变其功能。
Refactoring is the arranging of code to a better design, without changing its functionality.
重构是改变代码,不是为了改变它的工作方式,而是为了改变它的可读性、降低复杂性等。
这可能包括创建辅助方法、将大方法分成几个、将大类分成几个、重命名变量、方法和类,以及整个主机的其他东西使代码更容易理解。
Visual Studio 具有许多选项(例如重命名变量和方法)来帮助您重构(以及任何其他 IDE)。
当您觉得代码难以理解或神秘或过于复杂时,您应该使用它。
Refactoring is changing code not to change how it works, but to change its readability, reduce complexity, etc.
That might include making helper methods, splitting large methods into several, splitting large classes into several, renaming variables, methods and classes, and a whole host of other things to make the code more understandable.
Visual Studio has a host of options, like renaming variables and methods, to help you refactor (along with any other IDE).
You should use it when you feel that code is hard to understand or cryptic, or otherwise overly complex.
我正在重构此代码以提高可读性、降低复杂性并提高可维护性。这段代码不是.net,但你会明白的。
重构。
I'm refactoring this code to improve readability, reduce complexity and improve maintainability. This code is not .net but you will get the idea.
Refactored.
重构是针对程序员的,而不是针对用户的。它可以帮助程序员重新组织他们的代码。在重构的过程中,程序员大多会改变变量名、改变类名、添加方法,有时还会添加类。软件功能没有变化。
Refactoring is for programmers not for users. It helps the programmers to reorganize their code. In the process of refactoring, the programmers change the variable names, change the class names, can add methods mostly and sometimes add classes. There is no change in the software functionality.