Misplaced Pages

Code refactoring

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.

This is an old revision of this page, as edited by Bjorn Elenfors (talk | contribs) at 06:07, 18 October 2001. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 06:07, 18 October 2001 by Bjorn Elenfors (talk | contribs)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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, 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 (available online).

This is the best single reference for smelly code, I've ever seen.


The book Refactoring by Martin Fowler, in collaboration with Kent Beck, John Brant, Wililam Opdyke, and Don Roberts (ISBIN 0-201-48567-2, 1999 Addison Wesley Longman, Inc.) is

the classic reference. Martin Fowler also has a website, http://www.refactoring.org. Several good discussions are found at the WikiWeb at c2.org.


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.


Links:

What Is Refactoring (c2.com article)