Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

DRY

DRY stands for “Don’t Repeat Yourself.” It means defining each rule in one place and having the rest of the system use that definition, so a change doesn’t require updating several independent copies.

Also known as: Don't Repeat Yourself

What DRY is about

DRY is a design principle about where decisions live, not a rule against writing the same line twice. Suppose an application defines a password reset expiry as 20 minutes in its email template and also as 20 minutes in the code that checks the token. If the template is updated to say 30 minutes but the check isn’t, the product makes a promise it can’t keep. The problem is that two parts of the system independently define the same policy.

What a single source looks like

For the reset example, define the lifetime in one policy setting, calculate an expiration time when issuing the token, and use that expiration time both to build the email and to check the token later. The template is still responsible for wording, and the verifier is still responsible for rejecting expired tokens. They share the decision about when the token expires, not a single large function that handles both jobs.

The right place depends on what you’re sharing. A named setting works for a configurable value; a function works for a calculation; a schema can define a data format used by several clients. Generating client types from that schema can produce repeated text without creating multiple sources of truth. The key is that changes are made to the schema, not to the generated copies.

When similar code should stay separate

Use this test: if the requirement changes in one place, would it be a bug for the other place to stay as it is? A reset link and a shopping cart reservation might both last 20 minutes, but product owners should be able to change either duration on its own. A shared DEFAULT_TIMEOUT would hide that independence. Two clearly named settings make it visible, even if the values happen to match.

The cost of sharing matters, too. A small helper inside one application is easy to adopt. A shared library used by independently deployed services adds versioning and rollout work. Don’t introduce that dependency just to remove a few similar lines; first establish whether the services really implement the same policy and need it to evolve together.

How it comes up in interviews

In a code review exercise, identify the rule before proposing an extraction. Explain which callers should use it, what stays local, and how you’ll check that behavior hasn’t changed. If the two snippets represent separate policies, say what future change would affect one but not the other. That’s a stronger argument than counting duplicate lines.