Skip to content

Java DRY Principles#

What Is The DRY Principle?#

  • DRY stands for Don’t Repeat Yourself. It’s a software development principle with the goal of removing logic duplication.
  • The DRY code principle was originally made with software engineering in mind and coined by Andy Hunt and Dave Thomas in their book, The Pragmatic Programmer. They believed that every piece of knowledge must have a single, unambiguous, authoritative representation within a system. As the field of analytics engineering and data transformation develops, there’s a growing need to adopt software engineering best practices, including writing DRY code.

Benefit#

  • The advantages of the DRY principle include the following:
    • It makes the codebase easier to maintain since if we wanted to change the logic or add to it, we’d only need to change it in one place instead of multiple locations where the logic appears
    • It makes the code easier to read because there’ll be less redundancy in the code
  • It’s important to mention that misusing DRY (creating functions where we don’t need to, making unnecessary abstractions, and so on) can lead to more complexity in our code rather than simplicity.

Don't Be WET#

  • WET, which stands for Write Everything Twice, is the opposite of DRY. It's a tongue-in-cheek reference to code that doesn’t exactly meet the DRY standard. In a practical sense, WET code typically involves the repeated writing of the same code throughout a project, whereas DRY code would represent the repeated reference of that code.

See Also#

References#