Misplaced Pages

Code refactoring: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 23:21, 25 July 2002 editTobias Hoevekamp (talk | contribs)Extended confirmed users2,321 editsm "external link:"← Previous edit Revision as of 03:02, 29 March 2003 edit undoDwheeler (talk | contribs)Extended confirmed users2,916 edits Noted William F. Opdyke's 1993 PhD dissertation, minor improvements.Next edit →
Line 1: Line 1:
To <b>refactor</b> programming ] is to rewrite the code, to "clean it up." To <b>refactor</b> programming ] is to rewrite the code, to "clean it up."


Refactoring is the process of rewriting something to improve readability and comprehension with the explicit purpose of not changing the meaning. In the case of software, a refactoring is part of the cycle of create code, test code, refactor, test code, maintain code, test code, refactor, maintain code... and so on. Testing ensures that the code does what it is supposed to. 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, in order to make it easier for human maintenance in the future. Refactoring is the process of rewriting something to improve readability and comprehension with the explicit purpose of not changing the meaning. In the case of software, a refactoring is part of the cycle of create code, test code, refactor, test code, maintain code, test code, refactor, maintain code... and so on. Testing ensures that the code does what it is supposed to. 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, in order to make it easier for human maintenance
in the future.


An example of a simple refactoring is to change the name of a variable to 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 function. An even more complex refactoring is to replace an if conditional with polymorphism. An example of a simple refactoring is to change the name of a variable to 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 function. An even more complex refactoring is to replace an if conditional with polymorphism.
Line 8: Line 10:


The book <b>Refactoring</b> by ], in collaboration with ], ], ], and ] (ISBN 0-201-48567-2, 1999 Addison Wesley Longman, Inc.) is the classic reference. Martin Fowler also has a website, http://www.refactoring.com. Several good discussions are found at the WikiWeb at c2.org. The book <b>Refactoring</b> by ], in collaboration with ], ], ], and ] (ISBN 0-201-48567-2, 1999 Addison Wesley Longman, Inc.) is the classic reference. Martin Fowler also has a website, http://www.refactoring.com. Several good discussions are found at the WikiWeb at c2.org.
Although refactoring code has been done informally for years,
is the first known paper to specifically
examine refactoring, cataloguing common methods for refactoring and
expressly describing why refactoring is a useful technique.


To <b>refactor</b> text, in a WikiWiki, is to rewrite and often to reorganize the text completely or radically, sometimes dramatically shortening it, but in a way that preserves all the important, relevant content. In a <nowiki>WikiWiki</nowiki>, it is usually ''discussions'' that are refactored--with the purpose of making the discussion accessible to someone who is interested in the arguments made in the discussion, and the information to be gleaned from it, rather than the history of the discussion itself. To <b>refactor</b> text, in a WikiWiki, is to rewrite and often to reorganize the text completely or radically, sometimes dramatically shortening it, but in a way that preserves all the important, relevant content. In a <nowiki>WikiWiki</nowiki>, it is usually ''discussions'' that are refactored--with the purpose of making the discussion accessible to someone who is interested in the arguments made in the discussion, and the information to be gleaned from it, rather than the history of the discussion itself.

Revision as of 03:02, 29 March 2003

To refactor programming code is to rewrite the code, to "clean it up."

Refactoring is the process of rewriting something to improve readability and comprehension with the explicit purpose of not changing the meaning. In the case of software, a refactoring is part of the cycle of create code, test code, refactor, test code, maintain code, test code, refactor, maintain code... and so on. Testing ensures that the code does what it is supposed to. 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, in order to make it easier for human maintenance in the future.

An example of a simple refactoring is to change the name of a variable to 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 function. An even more complex refactoring is to replace an if conditional with polymorphism.

Many refactorings are meant to cure the ills listed in "How to Write Unmaintainable Code" by Roedy Green.

The book Refactoring by Martin Fowler, in collaboration with Kent Beck, John Brant, William Opdyke, and Don Roberts (ISBN 0-201-48567-2, 1999 Addison Wesley Longman, Inc.) is the classic reference. Martin Fowler also has a website, http://www.refactoring.com. Several good discussions are found at the WikiWeb at c2.org. 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, cataloguing common methods for refactoring and expressly describing why refactoring is a useful technique.

To refactor text, in a WikiWiki, is to rewrite and often to reorganize the text completely or radically, sometimes dramatically shortening it, but in a way that preserves all the important, relevant content. In a WikiWiki, it is usually discussions that are refactored--with the purpose of making the discussion accessible to someone who is interested in the arguments made in the discussion, and the information to be gleaned from it, rather than the history of the discussion itself.

Obviously, refactoring is difficult to do in such a way that will make all participants in a discussion happy. It requires intelligence, tact, excellent reading comprehension skills, good writing skills, and a lack of bias.


For policy on refactoring in Misplaced Pages, see editing policy. In the context of Misplaced Pages, usually talk pages are refactored, but occasionally, when an article has been developed in a particularly haphazard way, it needs to be changed so radically that the resulting change can be called a refactoring.

External Links:

What Is Refactoring (c2.com article)