开发者

Refactoring .NET code

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.


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


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:

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.


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


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.


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜