DRY(don't repeat yourself)軟件思想(1)

In software engineering, Don't Repeat Yourself (DRY) or Duplication is Evil (DIE) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures. The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." The principle has been formulated by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer. They apply it quite broadly to include "database schemas, test plans, the build system, even documentation."[1] When the DRY principle is applied successfully, a modification of any single element of a system does not change other logically-unrelated elements. Additionally, elements that are logically related all change predictably and uniformly, and are thus kept in sync. Besides using methods and subroutines in their code, Thomas and Hunt rely on code generators, automatic build systems, and scripting languages to observe the DRY principle across layers.

Also known as Single Source of Truth, this philosophy is prevalent in model-driven architectures, in which software artifacts are derived from a central object model expressed in a form such as UML. DRY code is created by data transformation and code generators, which allows the software developer to avoid copy and paste operations. DRY code usually makes large software systems easier to maintain, as long as the data transformations are easy to create and maintain.

Kent Beck has mentioned that he does not "subscribe to [DRY] for test code because [he] want[s] [his] tests to read like a story".


翻譯:

在軟件工程 , 不要編寫同一代碼(DRY)或重複勞動是一種浪費 ( DIE )是一個軟件開發的原則,其目的是減少重複信息,尤其是用在多層次的體系結構中 。 DRY原則的爲“每一個知識(此處處可理解爲代碼)都必須在系統內必須是單一的,明確的,權威的,具有代表性。” 該原則是由Andy Hunt 和 Dave Thomas在他們的著作《The Pragmatic Programmer》中提出的 。 他們將它應用在相當廣泛的領域,包括“ 數據庫架構, 軟件測試 ,系統架構,甚至是文件管理 。“ 當DRY的原則成功應用,在系統中,任何單一元素的修改不影響與其邏輯無關的元素。 此外,和元素邏輯相關的一切變化都是可以預見和統一,因此保持同步 。 除了使用這種方法(此處的method和subroutines是同一個意思,只是一個是面向對象的說法,一個是面向過程的說法),在他們的代碼, Thomas和Hunt 依靠代碼生成 ,自動生成系統,並依賴腳本語言,觀察DRY原則在跨層中的運用。

DRY這個思想被稱爲真理的一個來源(這裏上升到哲學高度) ,這種哲學是普遍的模型驅動架構(個人認爲可以理解爲分層複用的設計思想) ,這種軟件構件(的思想)來源於中間體( central object model是指硬件和應用程序中間的抽象接口模型)類似UML的的形式表示出來 。 通過 用DRY思想創建的數據轉換和代碼生成器,允許軟件開發人員,避免複製和粘貼操作。 DRY代碼通常使得大型軟件系統更容易維護,因爲數據轉換很容易創建和維護。

Kent Beck提到,他不“贊同用[DRY]去測試代碼,因爲[他]希望, [他的]測試,讀起來想個故事。”(這句話是說DRY分層反而導致了閱讀的不便利,讀起來不順,不知道我這個解釋對不對。)
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章