Advertisement

Refactoring

From Academic Kids

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

Contents

Refactoring code

In software engineering, the term refactoring is often used to describe modifying source code without changing its external behavior, and is sometimes informally referred to as "cleaning it up". Refactoring is often practiced as part of the software development cycle: developers alternate between adding new tests and functionality and refactoring the code to improve its internal consistency and clarity. Testing ensures that refactoring does not change the behavior of the code.

Refactoring is the part of code maintenance which doesn't fix 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.

The term is by analogy with the factorization of numbers and polynomials. For example, x2 − 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 bug and can be fixed separately from the problem of debugging 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. 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.

Refactoring is an important aspect of extreme programming.

Martin Fowler's book Refactoring is the classic reference. Although refactoring code has been done informally for years, William F. Opdyke's 1993 PhD dissertation is the first known paper to specifically examine refactoring. All of these resources provide a catalog of common methods for refactoring; a refactoring method has a description of how to apply the method and indicators for when you should (or should not) apply the method.

Refactoring is such an important concept that it has been identified as one of the most important software innovations (http://www.dwheeler.com/innovation/innovation.html) by author and commentator David A. Wheeler.

Common refactorings

Forth

The term 'factoring' has been used in the Forth community since at least the early 1980s. Chapter Six of 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 (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 [1] (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 [2] (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

See also

External links

ca:Refactoring de:Refactoring fr:Refactorisation nl:Refactoring es:Refactorizar ja:リファクタリング (プログラミング) pl:Refactoring zh:软件重构

Navigation

Academic Kids Menu

  • Art and Cultures
    • Art (http://www.academickids.com/encyclopedia/index.php/Art)
    • Architecture (http://www.academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (http://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (http://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools