# DRY, KISS and YAGNI

> Three short rules of thumb for writing code: do not repeat yourself, keep it simple, and do not build what you do not need yet. Plus SOLID.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 11 min

**After this lesson you can:**

- Remove a repeat with a function
- Choose the simplest design that works
- Say what the five SOLID rules are for

## Which rules of thumb keep code easy to change

Three short rules guide most everyday code. DRY means don't repeat yourself: each piece of logic should live in one place. KISS means keep it simple: pick the plainest design that does the job. YAGNI means you aren't gonna need it: do not build a feature until it is actually needed.

DRY comes from a 1999 book about the craft of writing code. The danger it guards against is a fix made in one copy and missed in another. If the same 5 lines of maths sit in 4 places, a change means 4 edits. Put them in one function and call it 4 times.

DRY is about the same knowledge, not the same-looking text. Two lines that happen to match today, but mean different things, can be left apart. Joining them forces them to change together, and one day they will need to differ.

KISS warns against clever code. A plain loop that anyone can follow beats a one-line trick that only its author understands. Simple code has fewer places for bugs to hide, and it is quicker to change. When two designs both work, pick the one a beginner could read.

YAGNI warns against building for a future that may never come. Code written for later still has to be read, tested and kept working now. Most of those later features never arrive, or arrive looking different. Build what this week needs, and keep the code easy to change.

SOLID is a set of five rules for the bigger building blocks of code, called classes. Each letter names one rule. You will meet classes once programs grow. For now, the first rule is the one to keep. It says each part of the code should have one job, and only one.

These are rules of thumb, not laws, and they can pull against each other. Squeezing out every repeat can make code less simple. The goal behind all of them is the same: code that the next person can read and change without fear.

## Which rule to reach for

1. **DRY.** Reach for it when you are about to paste the same logic a second time.
2. **KISS.** Reach for it when your solution needs a long comment to explain how it works.
3. **YAGNI.** Reach for it when you catch yourself saying we might need this one day.
4. **SOLID.** Reach for it later, once your programs are built from classes that work together.

![Two panels. Before: the tax sum is copied into cart, invoice and receipt, and the receipt copy still says 1.2 while the others say 1.15, marked missed when the rate changed. After: one function, with_tax, holds the sum once, and arrows from cart, invoice and receipt all call it.](https://learn.benibix.com/diagrams/prog-dry.svg)

### Example: Lucy skips the export button

Lucy's team asks for a sign-up form. She is tempted to add export to 4 file types as well, in case someone asks.

She builds only the form, in 2 days. Six months later, nobody has asked for an export. YAGNI saved her about a week of code she would have had to keep working.

**Words in this lesson:** [Don't Repeat Yourself (DRY)](https://learn.benibix.com/term/development/dry-principle), [KISS Principle](https://learn.benibix.com/term/development/kiss-principle), [You Aren't Gonna Need It (YAGNI)](https://learn.benibix.com/term/development/yagni), [SOLID Principles](https://learn.benibix.com/term/development/solid-principles)

> **The one thing to remember.** DRY puts each piece of logic in one place. KISS keeps it plain, and YAGNI stops you building it before it is needed.

**Question:** What does the YAGNI rule tell you to do?

**Answer:** Leave out a feature until it is actually needed. YAGNI stands for you aren't gonna need it. Build what is needed now, because code for an imagined future still costs time to read and keep working.

---

Source: https://learn.benibix.com/learn/development-concepts/dry-kiss-and-yagni
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
