CSC/ECE 517 Fall 2009/wiki 1a 7a HJ: Difference between revisions
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
Refactoring is motivated by the difficulty of adding new functionality to a program | Refactoring is motivated by the difficulty of adding new functionality to a program or fixing a bug in it. | ||
As we said before, after code refactoring, the program does the the exact same thing it did before. | |||
The differences are that the new code: | The differences are that the new code: | ||
Line 59: | Line 59: | ||
Here are some examples of Refactoring for JAVA | Here are some examples of Refactoring for JAVA | ||
==== Rename ==== | |||
First code | First code | ||
Line 81: | Line 81: | ||
==== Encapsulation ==== | |||
Line 88: | Line 88: | ||
==== Rename ==== | |||
Line 102: | Line 102: | ||
==== Encapsulation ==== | |||
Line 108: | Line 108: | ||
== Current IDE and Refactoring == | == Current IDE and Refactoring == | ||
=== Current Java IDE === | === Current Java IDE and Refactoring === | ||
Most of Java IDE support refactoring. | |||
Eclipse which is one of the most used JAVA IDE is | |||
=== Current Ruby IDE and Refactoring === | === Current Ruby IDE and Refactoring === | ||
Line 160: | Line 165: | ||
|- | |- | ||
|} | |} | ||
== Conclusion == | |||
Revision as of 04:06, 17 September 2009
Definition of code refactoring
According to 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 before, 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 [1] inspired of the site [2] and to the section 2.1.2 of the thesis of Thomas Corbat [3].
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
Examples of Refactoring for JAVA
Here are some examples of Refactoring for JAVA
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"); }
}
Encapsulation
Examples of refactoring for Ruby
Rename
def FirstMethod
puts("NC State");
end
Refactor by renaming
def NCSU
puts("NC State");
end
Encapsulation
Current IDE and Refactoring
Current Java IDE and Refactoring
Most of Java IDE support refactoring. Eclipse which is one of the most used JAVA IDE is
Current Ruby IDE and Refactoring
The following Current Ruby IDE do not support refactoring :
Ruby in Steel |
Arachno Ruby |
FreeRIDE |
Mondrian Ruby IDE |
RubyMine and Eclipse with Aptana are the only current Ruby IDE with refactoring support.
Ruby and JAVA Refactoring Tools : a small comparaison
JAVA | Ruby |
---|---|
Rename | Rename |
Move | Move |
Extract Class | Convert Local Variable or Field |
Extract Super Class | Extract Constant |
Encapsulate Field | |
Introduce Parameter |
Conclusion
The differences between the two languages JAVA and Ruby is the number of methods available for refactoring. JAVA has two times more options for refactoring. However, refactoring tools for both JAVA and Ruby are integrated into some IDE like Eclipse.
References
[1] Refactoring and version control, CSC517, NCSU, Dr. Ed Gehringer
http://courses.ncsu.edu/csc517/common/lectures/notes/lec3-f09.pdf
[2] http://www.refactoring.com
[3] Refactoring Support for the Eclipse Ruby Development Tools
HSR, University of Applied Science Rapperswil Diploma Thesis of Thomas Corbat, Lukas Felber and Mirko Stocker Summary : http://subs.emis.de/LNI/Proceedings/Proceedings106/gi-proc-106-039.pdf Complete Thesis: http://r2.ifs.hsr.ch/rubyrefactoring.pdf
[4] Forum for help on refactoring in Ruby
http://refactormycode.com/codes/recent/ruby
[5] Forum for help on refactoring in Java
http://refactormycode.com/codes/recent/java
[6] http://www.slideshare.net/jweiss/refactoring-ruby-on-rails-applications