Rule of Three (Computer Programming)

栏目: IT技术 · 发布时间: 6年前

内容简介: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)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

惡血

惡血

[美] 约翰·凯瑞鲁 / 林锦慧 / 商業周刊 / 2018-9-20 / NT$430

--新創神話!?揭露3000億獨創醫療科技的超完美騙局-- 她被譽為女版賈伯斯、《富比世》全球最年輕的創業女富豪, 如何用「一滴血」顛覆血液檢測、翻轉醫療產業? 一項即將改變你我健康的醫療檢測新科技, 而它的技術來自--謊言! ◎即將改編成電影,由奧斯卡影后珍妮佛‧勞倫斯(Jennifer Lawrence)主演 ◎榮登《紐約時報》、《出版人週刊》暢銷榜 ......一起来看看 《惡血》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

html转js在线工具
html转js在线工具

html转js在线工具