CSC/ECE 517 Fall 2009/wiki 1a 7a HJ: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Definition of code refactoring ==
== Definition of code refactoring ==


According Wikipedia : "Code refactoring is the process of changing a program's internal structure without modifying its external functional behavior or existing functionality with the goals of readability, maintainability, performance, extensibility and simplicity."
According Wikipedia : "Code refactoring is the process of changing a program's internal structure without modifying its external functional behavior or existing functionality with the goals of readability, maintainability, performance, extensibility and simplicity."
Line 29: Line 30:


== Common Refactorings Tools ==
== Common Refactorings Tools ==


Here is a list of some examples of refactoring techniques used. For further information, the reader please refer to Lecture 3 of CSC 517 of Dr. Gehringer and to the section 2.1.2 of the thesis of Thomas Corbat.
Here is a list of some examples of refactoring techniques used. For further information, the reader please refer to Lecture 3 of CSC 517 of Dr. Gehringer and to the section 2.1.2 of the thesis of Thomas Corbat.
Line 54: Line 56:


== Examples of Refactoring for JAVA ==
== Examples of Refactoring for JAVA ==
Here are some examples of Refactoring for JAVA
1) Rename
First code
public class rename_Method
{
    static void WrongRenameMethod() {
        System.out.println("NC State");
    }
}
Refactor by renaming
public class rename_Method
{
    static void ncsu(){
        System.out.println("NC State");
    }
}
def FirstMethod
    puts("NC State");
end
Refactor by renaming
def NCSU
    puts("NC State");
2) Encapsulation
After encapsulation
Public class Point
{
  int x,y;
  Public Point(int coordx, int coordy){
        x = coordx;
        y = coordy;
  }

Revision as of 20:41, 8 September 2009

Definition of code refactoring

According Wikipedia : "Code refactoring is the process of changing a program's internal structure without modifying its external functional behavior or existing functionality with the goals of readability, maintainability, performance, extensibility and simplicity."


Goals of refactoring

Refactoring is motivated by the difficulty of adding new functionality to a program. or fixing a bug in it.

As we said berfore, after code refactoring, the program does the the exact same thing it did before.

The differences are that the new code:

1) is easier to read and so to understand
2) contains less duplication
3) is less complex
4) is more flexible towards future changes
5) could lead to a faster compilation time


Common Refactorings Tools

Here is a list of some examples of refactoring techniques used. For further information, the reader please refer to Lecture 3 of CSC 517 of Dr. Gehringer and to the section 2.1.2 of the thesis of Thomas Corbat.

1) Rename : Methods, Fields, Packages, Projects, Parameters, Local Variables
2) Encapsulate Field
3) Move : Method, Field
4) Pull up : Field, Method
5) Push down : Field, Method
6) Extract : Method, Class, Constant, Local Variables
7) Convert Local Variables to Field
8) Change Method Signature


Examples of Refactoring for JAVA

Here are some examples of Refactoring for JAVA

1) Rename

First code

public class rename_Method {

   static void WrongRenameMethod() {
       System.out.println("NC State");
   }

}


Refactor by renaming

public class rename_Method {

   static void ncsu(){
       System.out.println("NC State");
   }

}







def FirstMethod

    puts("NC State");

end

Refactor by renaming

def NCSU

    puts("NC State");


2) Encapsulation

After encapsulation

Public class Point {

  int x,y;
  Public Point(int coordx, int coordy){
       x = coordx;
       y = coordy;
  }