内容简介:Duplication is considered a bad practice in programming because it makes the code harder tomaintain. When the rule encoded in a replicated piece of code changes, whoever maintains the code will have to change it in all places correctly.However, choosing an
Rule of three ( "Three strikes and you refactor" ) is acode refactoring rule of thumb to decide when similar pieces of code should be refactored to avoid duplication. It states that two instances of similar code don't require refactoring, but when similar code is used three times, it should be extracted into a new procedure. The rule was popularised byMartin Fowler in Refactoring and attributed to Don Roberts.
Duplication is considered a bad practice in programming because it makes the code harder tomaintain. When the rule encoded in a replicated piece of code changes, whoever maintains the code will have to change it in all places correctly.
However, choosing an appropriate design to avoid duplication might benefit from more examples to see patterns in. Attempting premature refactoring risks selecting a wrong abstraction, which can result in worse code as new requirements emergeand will eventually need to be refactored again.
The rule implies that the cost of maintenance certainly outweighs the cost of refactoring and potential bad design when there are three copies, and may or may not if there are only two copies.
See also [ edit ]
References [ edit ]
以上所述就是小编给大家介绍的《Rule of Three (Computer Programming)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
C++标准库(第2版)
Nicolai M. Josuttis / 侯捷 / 电子工业出版社 / 2015-6 / 186.00元
《C++标准库(第2版)》是全球C++经典权威参考书籍时隔12年,基于C++11标准的全新重大升级。标准库提供了一组公共类和接口,极大地拓展了C++语言核心功能。《C++标准库(第2版)》详细讲解了每一标准库组件,包括其设计目的和方法、复杂概念的剖析、实用而高效的编程细节、存在的陷阱、重要的类和函数,又辅以大量用C++11标准实现的实用代码范例。除覆盖全新组件、特性外,《C++标准库(第2版)》一......一起来看看 《C++标准库(第2版)》 这本书的介绍吧!