DEV Community

Cover image for DRY Principle in 100 Seconds
Richard Wynn
Richard Wynn

Posted on

8

DRY Principle in 100 Seconds

💡 What does DRY stand for?

DRY stand for Don't Repeat Yourself, a basic principle of software development aimed at reducing repetition of information.
Alt Text

👤 Origination

The principle has been formulated by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer. It is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system".
Alt Text

⭐ Why DRY?

  • Write code once, use it often.
  • Change code in one place, see the change in all instances.
  • Less code is good: It saves time and effort, is easy to maintain, and also reduces the chances of bugs.

DRY Violations

  • Writing/ Copying and pasting the same code or logic again and again. Alt Text

💡 How to DRY?

  • Divide your code and logic into smaller reusable units and use that code by calling it where you want.
  • Put business rules, long expressions, if statements, math formulas, metadata, etc. in only one place.

📱 Keep in Touch

If you like this article, don't forget to follow and stay in touch with my latest ones in the future by following me via:

📰 Others

Be interested? 😃 You can visit the links below read my other posts in my programming principles series

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay