Rule of three (programming)

Rule of three (programming)

Rule of three is a code Refactoring rule of thumb to decide when a replicated piece of code should be replaced by a new procedure. It states that you are allowed to copy and paste the code once, but that when the same code is replicated three times, it should be extracted into a new procedure. The rule was introduced by Martin Fowler in Refactoring [Refactoring: Improving the Design of Existing Code by Martin Fowler (ISBN: 978-0201485677)] and attributed to Don Roberts.

Duplication in programming is a bad practice because it makes the code harder to maintain. When the rule encoded in a replicated piece of code changes, whoever maintains the code will have to change it in all places correctly. This process is error-prone and often leads to problems. If the code exists in only one place, then it can be easily changed there.

ee also

* Don't repeat yourself (DRY)
* Refactoring

References

External links

* [http://c2.com/cgi/wiki?DontRepeatYourself DRY (c2.com)]
* [http://c2.com/cgi/wiki?OnceAndOnlyOnce Once and Only Once (c2.com)]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Rule of Three — may refer to: *Rule of three (medicine), judgement of likelihood of harm in drug trials. *Rule of three (Wiccan), a tenet of Wicca *Rule of three (mathematics), a computation method in mathematics *Rule of three (writing), a principle of writing… …   Wikipedia

  • Rule of three (C++ programming) — The rule of three (also known as the Law of The Big Three or The Big Three) is a rule of thumb in C++ that claims that if a class or struct defines one of the following it should probably explicitly define all threecite book last = Stroustrup… …   Wikipedia

  • Three Laws of Robotics — In science fiction, the Three Laws of Robotics are a set of three rules written by Isaac Asimov, which almost all positronic robots appearing in his fiction must obey. Introduced in his 1942 short story Runaround , although foreshadowed in a few… …   Wikipedia

  • Constructor (object-oriented programming) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Abstraction principle (programming) — In software engineering and programming language theory, the abstraction principle (or the principle of abstraction) is a basic dictum that aims to reduce duplication of information in a program (usually with emphasis on code duplication)… …   Wikipedia

  • Big Three — The term Big Three may refer to:Government and education* Big Three (colleges), Harvard, Yale, and Princeton * The Big Three Allied leaders of World War I, the dominant diplomatic figures at the Paris Peace Conference of 1919, Lloyd George,… …   Wikipedia

  • List of programming languages by category — Programming language lists Alphabetical Categorical Chronological Generational This is a list of programming languages grouped by category. Some languages are listed in multiple categories. Contents …   Wikipedia

  • Constraint logic programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computing …   Wikipedia

  • Dataflow programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computing …   Wikipedia

  • Comparison of programming languages (syntax) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”