Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
service
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
Freenet DSL
Who's Online
5 user(s) are online (5 user(s) are browsing encyclopedia)

Members: 0
Guests: 5

more...
partner

Refactoring

Refactoring is the process of rewriting a computer program or other written material to improve its readability or structure with the explicit purpose of keeping its meaning or behavior.

=Refactoring code=

In software engineering, the term refactoring means modifying source code without changing its external behavior, and is sometimes informally referred to as cleaning it up . In Extreme programming and other agile methodologies refactoring is an integral part of the ensures that refactoring does not make the code stop working.

Refactoring does not fix computer bugs or add new functionality. Rather it is designed to improve the understandability of the code or change its structure and design, and remove dead code, to make it easier for human maintenance in the future. In particular, adding new behavior to a program might be difficult with the program s given structure, so a developer might refactor it first to make it easy, and then add the new behavior.

An example of a trivial refactoring is to change a variable name into something more meaningful, such as from a single letter i to interestRate . A more complex refactoring is to turn the code within an if block into a Subroutine. An even more complex refactoring is to replace an if conditional with polymorphism (computer science). While cleaning up code has happened for decades, the key insight in refactoring is to intentionally clean up code separately from adding new functionality, using a known catalogue of common useful refactoring methods, and then separately testing the code (knowing that any behavioral changes indicate a bug). The new aspect is explicitly wanting to improve an existing design without altering its intent or behavior.

The term is by analogy with the Factorization of numbers and polynomials. For example, x 2 − 1 can be factored as ( x + 1)( x − 1), revealing an internal structure that was previously not visible (such as the two roots at +1 and -1). Similarly, in software refactoring, the change in visible structure can often reveal the hidden internal structure of the original code.

Refactoring is done as a separate step, to simplify testing. At the end of the refactoring, any change in behavior is clearly a computer bug and can be fixed separately from the problem of Debugging the new behavior.

s for when you should (or should not) apply the method.

Refactoring is such an important .

=Common refactorings=

  • Change Method Signature
  • Convert Local Variable to Field
  • Encapsulate Field
  • Extract Class
  • Extract Interface
  • Extract Local Variable
  • Extract Method (to turn part of a larger method (computer science) into a new method. By breaking down code in smaller pieces, it is more easily understandable)
  • Generalize Type
  • Inline (Refactoring)
  • Introduce Factory
  • Introduce Parameter
  • Pull Up refactoring
  • Push Down
  • Rename Method (changing the name of a method into a new one that better reveals its purpose).
  • Break down large functions - Function (programming)s that grow in use also grow in size. After a certain point, it becomes clear that functions can benefit from using functions themselves. Your eyes probe the function looking for a likely candidate to relocate elsewhere. This candidate is chosen for being the largest stretch of code that really has nothing to do with the enclosing function. This lets us easily think up a name that explains what the new function does without having to resort to something contrived just to distinguish it from the original function. (This section is originally from Perl Design Patterns Book).
  • =Forth=

    The term factoring has been used in the Forth programming language community since at least the early 1980s. Chapter Six of Leo Brodie s book Thinking Forth (1984) is dedicated to the subject.

    In Forth, factoring has essentially the same meaning that refactoring does in extreme programming — to break down a Function (programming) (a word in Forth) into smaller, more easily maintained functions.

    =Refactoring other text=

    The term refactoring originated in computer programming, but the concept has also been applied when modifying any text.

    On Wiki websites, refactoring refers to the process of rewriting and reorganizing text to shorten it while preserving content. This particularly applies to discussions , which thus can be made accessible to people who are interested in the arguments made in the discussion, and the information to be gleaned from it, rather than the history of the discussion itself. Refactoring can be difficult to do in such a way that it makes all participants of a discussion happy.

    =Etymology=

    The first known use of the term refactoring in the published literature was in the article, Refactoring: An Aid in Designing Application Frameworks and Evolving Object-Oriented Systems , Proceedings of the Symposium on Object Oriented Programming Emphasizing Practical Applications (SOOPPA) September, 1990, ACM by William F. Opdyke and Ralph E. Johnson [http://www.cs.ucd.ie/staff/meloc/home/papers/thesis/Chapter2.pdf]. William Opdyke s Ph.D. thesis on Refactoring Object-Oriented Framework , University of Illinois, was published in 1992 [http://martinfowler.com/bliki/EtymologyOfRefactoring.html]. The term refactoring was almost certainly used before then. Refactoring as a technique was definitely used before then.

    As a neologism, it is clearly a reference to mathematical factoring.

    =References=

  • Martin Fowler: Refactoring. Improving the Design of Existing Code , Addison-Wesley Professional 1999, ISBN 0201485672
  • William C. Wake: Refactoring Workbook , Addison-Wesley, ISBN 0-321-10929-5
  • Joshua Kerievesky: Refactoring To Patterns , Addison-Wesley, ISBN 0321213351
  • =See also=

  • Code review
  • Peer review
  • Design pattern (computer science)
  • =External links=

    *[http://c2.com/cgi/wikiWhatIsRefactoring What Is Refactoring] (c2.com article) *[http://www.refactoring.com/ Martin Fowler s homepage about refactoring] *[ftp://st.cs.uiuc.edu/pub/papers/refactoring/opdyke-thesis.ps.Z 1993 PhD dissertation] by William F. Opdyke *[http://www.theserverside.com/articles/article.tssl=AspectOrientedRefactoringPart1 Aspect-Oriented Refactoring] by Ramnivas Laddad *[http://csdl.computer.org/comp/trans/ts/2004/02/e2toc.htm A Survey of Software Refactoring] by Tom Mens and Tom Tourwé *[http://mindprod.com/jgloss/unmain.html How to Write Unmaintainable Code] by Roedy Green *[http://www.refactoring.com/tools.html Refactoring Tools] *[http://www.refactoring.com/catalog/index.html Refactorings] - alphabetical list *[http://industriallogic.com/xp/refactoring/catalog.html Refactoring To Patterns Catalog] *[http://citeseer.ist.psu.edu/cisq=refactoring Citations from CiteSeer] *[http://www.methodsandtools.com/archive/archive.phpid=4 Refactoring Java Code] *[http://www.localpin.com/info/en/computers/programming/methodologies/refactoring/index.htm General Refactoring links]