The DRY (don't repeat yourself) principle is a best practice in software development that recommends software engineers do something once, and only once. The concept, which is often credited to Andrew Hunt and David Thomas, authors of "The Pragmatic Programmer," is the tongue-in-cheek opposite of the WET principle, which stands for "write everything twice." The DRY principle encourages developers to think about how to improve the maintainability of code during all phases of its lifecycle. When the principle has been followed, a software developer is able to change code in one place and have the change automatically applied to every instance of the code in question. According to the DRY principle, every discrete chunk of knowledge should have one unambiguous, authoritative representation within a system. The goal of the DRY principle is to lower technical debt by eliminating redundancies in process and logic whenever possible. Redundancies in process To prevent redundancies in processes (actions required to achieve a result), followers of the DRY principle seek to ensure that there is only one way to complete a particular process. Automating the steps wherever possible also reduces redundancy, as well as the number of actions required to complete a task. Redundancies in logic To prevent redundancies in logic (code), followers of the DRY principle use abstraction to minimize repetition. Abstraction is the process of removing characteristics until only the most essential characteristics remain. |
No comments:
Post a Comment