KISS
easy 40 minKeep it simple: choose the design with the fewest parts that still does the whole job, edge cases included.
Video lesson · Chapter 1 of 6
Make a prediction
KISS
1:03Reel
More reels
One idea each, a minute or less.
KISS or YAGNI?
0:31Reel
Theory
Read or listen first. About 3 min.
What it is
KISS means keep it simple, stupid. Simplicity is a goal of the design, and complexity that serves no requirement is removed. Kinder readings exist, such as keep it short and simple.
Simple means few parts, few links between them, and each part easy to explain. It does not mean short at any price, and it does not mean incomplete. A clever line that nobody can read is short and not simple. A function that forgets the empty list is simple and wrong.
So the target is: the fewest parts that fully solve the problem we have. Some difficulty comes from the problem itself and stays. The rest we added ourselves, and that part is what KISS attacks.
Why it exists
A reader must hold the parts of a program in their head. With each layer there is one more file to open, one more name to learn and one more place where a bug may sit.
Simple code is easier to test, because it has fewer paths. It is easier to fix at three in the morning. And it is easier to change, which surprises people: the flexible design guesses the next change, and the simple one has less in the way of any change.
In an interview the time is short. A simple core that works after 25 minutes beats a fine set of interfaces without a working method.
A short history
1938
Wikipedia's article reports that forms of the saying were seen in American English by at least this year.
1960
The U.S. Navy has a Project KISS. The phrase is also linked to the aircraft engineer Kelly Johnson of Lockheed, whose team had to design a jet that an average mechanic could repair with a handful of tools.
1976
Thomas McCabe publishes cyclomatic complexity, a count of the paths through a piece of code.
1978
Doug McIlroy writes down the Unix style: make each program do one thing well.
1984
Edsger Dijkstra notes in EWD 896 that simplicity is a great virtue, that it needs hard work, and that complexity sells better.
1986
Fred Brooks separates essential complexity (of the problem) from accidental complexity (of our tools and choices) in No Silver Bullet.
2004
The Zen of Python becomes PEP 20. It prefers simple to complex, and complex to complicated.
2011
Rich Hickey's talk Simple Made Easy: simple is about how few things are tied together, easy is about what is near to us.
Words to know
- Essential complexity
- Difficulty that comes from the problem. It cannot be removed, only arranged.
- Accidental complexity
- Difficulty that we added. It can be removed.
- Over-engineering
- More machinery than the problem needs.
- Indirection
- A step between the question and the answer, such as a wrapper or an interface.
- Cyclomatic complexity
- The number of decisions in a function plus one. Roughly: how many tests it needs.
- Guard clause
- An early return or error for a special case, so that the main path is not nested.
- Simplistic
- Too simple: part of the job is missing.
- Innovation token
- Dan McKinley's picture: a team can afford only a few new and unusual tools.
- Simple and easy
- Simple: little is tied together. Easy: we know it already.
The solution, twice
Reach the regular design first. Then go where a FAANG interviewer digs.
How it works
Step through the idea, or press Play.
State the job. One sentence
Understand it
Start here
The marble machine and the bowl
Asha has a party. Each guest should get one marble at the door. Max has an idea, and some gutter pipe.
Frames 2 to 4 are over-engineering, frame 5 is KISS, frame 6 is the mistake on the other side, and frame 7 shows when to add.
The smell
Hello, with four classes
The task: greet a person by name. Somebody thought: what if there are more kinds of greeting one day? There is one kind today.
interface GreetingStrategy { String greet(String name);}class FormalGreeting implements GreetingStrategy { public String greet(String name) { return "Hello, " + name; } // the work}class GreetingFactory { GreetingStrategy create(String type) { if ("formal".equals(type)) return new FormalGreeting(); throw new IllegalArgumentException(type); }}class GreetingService { private final GreetingFactory factory; GreetingService(GreetingFactory factory) { this.factory = factory; } String sayHello(String name) { return factory.create("formal").greet(name); }}// use: new GreetingService(new GreetingFactory()).sayHello("World")static String greet(String name) { return "Hello, " + name;}// use: greet("World")Four boxes for one line
1/4The work
One class builds the text. This is the whole requirement.
usesimplements
How it works
The reader pays for each hop
What a reader follows before
And after
Tasks and ways to do them
| Task | Over-engineered | KISS |
|---|---|---|
| Print Hello | Factory, strategy, printer | print("Hello") |
| Is a number even? | Turn it into binary text, look at the last letter | n % 2 == 0 |
| Toggle a switch | value ? false : true | !value |
| Sum of a list | Own iterator class with hasNext and next | sum(items), a loop, or reduce |
| Largest value | Class MaxFinder with process and getMax | max(items), std::max_element |
| Reverse a text | Own loop with a reserved buffer | The library call |
| Is it a date? | A long pattern that accepts 31 February | The date library, which knows the calendar |
import refrom datetime import datetimedef date_by_pattern(text): return bool(re.match(r"^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/(19|20)\d{2}$", text))def date_by_library(text): try: datetime.strptime(text, "%m/%d/%Y") return True except ValueError: return Falsefor text in ("02/28/2026", "02/31/2026", "1/2/2026"): print(text, date_by_pattern(text), date_by_library(text))KISS
- A direct answer to a direct problem
- Complexity when a requirement asks for it
- A new colleague can read it
- Can be explained in one sentence
Over-engineering
- A factory for a single class
- A strategy for one algorithm
- Ten layers for create, read, update, delete
- What if we need to ...
The line below
Simple is not simplistic
people = ["Asha", "Lee", "Max"]# Too simple: crashes for an empty list, and asks people who are away.def simplistic(people, week): return people[week % len(people)]# Simple: one rule, its edges handled, nothing more.def cleaner(people, week, away=()): for step in range(len(people)): person = people[(week + step) % len(people)] if person not in away: return person return Noneprint([simplistic(people, w) for w in range(4)])print([cleaner(people, w, away={"Lee"}) for w in range(4)])print(cleaner([], 3), cleaner(people, 0, away=set(people)))Too complicated would be a RotationStrategy with a registry, an event for each choice and a settings file. We meet it in the solution. The three versions are the machine, the bowl and the tray.
Signs that a design is too complicated
No single sentence
You cannot say what the code does in one sentence.
A week to understand
A new colleague needs days for a small feature.
More patterns than logic
Names like Factory, Manager and Provider, and little that decides.
Problems you do not have
Code for a million users in a club of forty.
Long reviews
The review is about how it works, and not whether it is right.
Tests harder than code
Ten mocks to check one sum.
Two sorts
Which complexity is whose?
Essential or accidental?
| In the kitchen rota | Sort | What to do |
|---|---|---|
| People go on holiday | Essential | Model it: away |
| Everybody may be away | Essential | Return nobody, let the caller say so |
| Four interfaces with one class each | Accidental | Remove |
| Weeks begin on Monday here and on Sunday there | Essential, if both countries use it | Ask first |
| A message queue between two functions of one program | Accidental | Call the function |
| Two services that must agree | Essential after the split, accidental if the split was not needed | Ask why they were split |
May this part stay?
Tools
Seven ways to make code simpler
- 1
Delete
The simplest code is the code that is not there. Remove options nobody sets.
- 2
Use the library
Sorting, dates, parsing and money types have solved edges.
- 3
Return early
Guard clauses move special cases out of the way.
- 4
Use data
A table replaces a chain of branches that differ in values.
- 5
Merge thin layers
A class that only forwards calls is joined with its neighbour.
- 6
Name things
One good name removes a comment and a question.
- 7
Narrow the input
Check at the border. Inside, the special cases do not exist.
const isEmptyLong = (s: string | null) => s !== null && s !== undefined && s.length === 0;const isEmptyShort = (s: string | null) => !s;isEmptyLong(null); // falseisEmptyShort(null); // true: not the same questionisEmptyShort(""); // trueconst toggleLong = (v: boolean) => (v ? false : true);const toggleShort = (v: boolean) => !v; // here both are equalThe kitchen rota should be able to send a reminder. What do you build?
BreaksA plugin system for channels
- How
- Interface, registry, config for mail, chat and SMS.
- Limit
- Only mail was asked for. Three of four parts are guesses.
- Choose when
- When others must add channels.
WorksSend mail inside cleaner
- How
- The function chooses and sends.
- Limit
- Choosing can no longer be tested without sending. Two jobs are tied together, so this is shorter but not simpler.
- Choose when
- A throwaway script.
StrongTwo plain functions
- How
cleanerdecides,remind(person, send_mail)sends. The caller joins them.- Limit
- One more name.
- Choose when
- Deciding and acting change separately.
Grow on a trigger
Neighbours
How it fits with other principles
| Principle | Relation |
|---|---|
| YAGNI | YAGNI asks whether to build something now. KISS asks how to build what is needed |
| DRY | A shared helper with many flags is dry and not simple. Two plain functions may be better |
| Open/closed | An extension point is worth its price when kinds really grow |
| Separation of concerns | More pieces can be simpler, if they are less tied together |
| Anti-patterns | The god class is the other extreme: one part, everything tied |
Summary
The whole topic in one minute.
KISS asks for the fewest parts that do the whole job. Not fewer lines at any price, and not fewer edge cases.
Give each part an owner among the requirements. A class, layer or option without one goes out. If you cannot say in one sentence what the code does, look again.
Start plain, know the number or the event that would force more, and add it when that happens.
- The fewest parts that do the whole job.
- Simple is not short, and not incomplete.
- Every part names its requirement, or it goes.
- Essential complexity is modelled, accidental complexity is removed.
- Prefer the library, early returns, data, and two plain functions.
- Know the trigger that will make you add more.