重构.NET代码

发布于 2024-10-13 00:38:01 字数 64 浏览 1 评论 0原文

我不知道重构是什么。如何使用以及何时使用?使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

心凉怎暖 2024-10-20 00:38:01

重构是修改代码以增强其可维护性而不改变其行为的做法。

例如,您可以将变量从“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

你是暖光i 2024-10-20 00:38:01

重构只不过是在不改变代码功能的情况下重新编写代码。

这通常意味着重命名变量以使它们更有意义、重新组织源代码、将大型方法分解为较小的方法以及其他(内部)更改。

这简化了代码,使其更易于理解和测试。如果做得正确,最终的结果是“更好”的代码,更容易维护和理解。

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.

东京女 2024-10-20 00:38:01

请参阅代码重构

代码重构的过程是
更改计算机程序的源代码
代码而不修改其外部
功能行为,以便
改善一些非功能性的问题
软件的属性。优点
包括改进的代码可读性和
降低复杂性以改善
源代码的可维护性,如
以及更具表现力的内部
架构或对象模型
提高可扩展性。

Please see Code refactoring:

Code refactoring is the process of
changing a computer program's source
code without modifying its external
functional behavior in order to
improve some of the nonfunctional
attributes of the software. Advantages
include improved code readability and
reduced complexity to improve the
maintainability of the source code, as
well as a more expressive internal
architecture or object model to
improve extensibility.

堇年纸鸢 2024-10-20 00:38:01

重构是将代码安排为更好的设计,而不改变其功能。

Refactoring is the arranging of code to a better design, without changing its functionality.

峩卟喜欢 2024-10-20 00:38:01

重构是改变代码,不是为了改变它的工作方式,而是为了改变它的可读性、降低复杂性等。

这可能包括创建辅助方法、将大方法分成几个、将大类分成几个、重命名变量、方法和类,以及整个主机的其他东西使代码更容易理解。

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.

如果没结果 2024-10-20 00:38:01

我正在重构此代码以提高可读性、降低复杂性并提高可维护性。这段代码不是.net,但你会明白的。

main(){
   int x=0,y[14],*z=&y;*(z++)=0x48;*(z++)=y[x++]+0x1D;
   *(z++)=y[x++]+0x07;*(z++)=y[x++]+0x00;*(z++)=y[x++]+0x03;
   *(z++)=y[x++]-0x43;*(z++)=y[x++]-0x0C;*(z++)=y[x++]+0x57;
   *(z++)=y[x++]-0x08;*(z++)=y[x++]+0x03;*(z++)=y[x++]-0x06;
   *(z++)=y[x++]-0x08;*(z++)=y[x++]-0x43;*(z++)=y[x]-0x21;
   x=*(--z);while(y[x]!=NULL)putchar(y[x++]);
 }

重构。

int main()
{
   printf("Hello, world!\n");
   return 0;
}

I'm refactoring this code to improve readability, reduce complexity and improve maintainability. This code is not .net but you will get the idea.

main(){
   int x=0,y[14],*z=&y;*(z++)=0x48;*(z++)=y[x++]+0x1D;
   *(z++)=y[x++]+0x07;*(z++)=y[x++]+0x00;*(z++)=y[x++]+0x03;
   *(z++)=y[x++]-0x43;*(z++)=y[x++]-0x0C;*(z++)=y[x++]+0x57;
   *(z++)=y[x++]-0x08;*(z++)=y[x++]+0x03;*(z++)=y[x++]-0x06;
   *(z++)=y[x++]-0x08;*(z++)=y[x++]-0x43;*(z++)=y[x]-0x21;
   x=*(--z);while(y[x]!=NULL)putchar(y[x++]);
 }

Refactored.

int main()
{
   printf("Hello, world!\n");
   return 0;
}
¢好甜 2024-10-20 00:38:01

重构是针对程序员的,而不是针对用户的。它可以帮助程序员重新组织他们的代码。在重构的过程中,程序员大多会改变变量名、改变类名、添加方法,有时还会添加类。软件功能没有变化。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文