AlgoViz

KISS

easy 40 min

Keep 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

0:00 / 4:27

KISS

1:03Reel

More reels

One idea each, a minute or less.

Play all in Bytesized Learning

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

  1. 1938

    Wikipedia's article reports that forms of the saying were seen in American English by at least this year.

  2. 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.

  3. 1976

    Thomas McCabe publishes cyclomatic complexity, a count of the paths through a piece of code.

  4. 1978

    Doug McIlroy writes down the Unix style: make each program do one thing well.

  5. 1984

    Edsger Dijkstra notes in EWD 896 that simplicity is a great virtue, that it needs hard work, and that complexity sells better.

  6. 1986

    Fred Brooks separates essential complexity (of the problem) from accidental complexity (of our tools and choices) in No Silver Bullet.

  7. 2004

    The Zen of Python becomes PEP 20. It prefers simple to complex, and complex to complicated.

  8. 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.

Step 1 of 4

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.

One marble for each guest
1 marbleeach

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.

Java
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")
Before. An interface, a class, a factory and a service. The work is one line, in the middle.
Java
static String greet(String name) {    return "Hello, " + name;}// use: greet("World")
After. When a second greeting is asked for, this method is easy to change: there is one.

Four boxes for one line

FormalGreeting+ greet(name)

1/4The work

One class builds the text. This is the whole requirement.

usesimplements

The test: point at each box and name the requirement. Three times there is none.

How it works

The reader pays for each hop

What a reader follows before

And after

The same answer. The computer does not mind the hops. The person who looks for a bug does.

Tasks and ways to do them

TaskOver-engineeredKISS
Print HelloFactory, strategy, printerprint("Hello")
Is a number even?Turn it into binary text, look at the last lettern % 2 == 0
Toggle a switchvalue ? false : true!value
Sum of a listOwn iterator class with hasNext and nextsum(items), a loop, or reduce
Largest valueClass MaxFinder with process and getMaxmax(items), std::max_element
Reverse a textOwn loop with a reserved bufferThe library call
Is it a date?A long pattern that accepts 31 FebruaryThe date library, which knows the calendar
Often the simple way is the library way: somebody else has already handled the edges.
Python
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))
The pattern is longer and wrong. The library is shorter and right. It is a little more tolerant: it also takes 1/2/2026, so check that if the format must be strict.
Edit and run it in your browser

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

Python
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)))
Three ways to choose who cleans the kitchen this week. The middle one is simple and whole.
Edit and run it in your browser

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 rotaSortWhat to do
People go on holidayEssentialModel it: away
Everybody may be awayEssentialReturn nobody, let the caller say so
Four interfaces with one class eachAccidentalRemove
Weeks begin on Monday here and on Sunday thereEssential, if both countries use itAsk first
A message queue between two functions of one programAccidentalCall the function
Two services that must agreeEssential after the split, accidental if the split was not neededAsk why they were split
The same part may be essential in one product and accidental in another. The requirement decides.

May this part stay?

Tools

Seven ways to make code simpler

  1. 1

    Delete

    The simplest code is the code that is not there. Remove options nobody sets.

  2. 2

    Use the library

    Sorting, dates, parsing and money types have solved edges.

  3. 3

    Return early

    Guard clauses move special cases out of the way.

  4. 4

    Use data

    A table replaces a chain of branches that differ in values.

  5. 5

    Merge thin layers

    A class that only forwards calls is joined with its neighbour.

  6. 6

    Name things

    One good name removes a comment and a question.

  7. 7

    Narrow the input

    Check at the border. Inside, the special cases do not exist.

TypeScript
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 equal
Simple code must also mean the same. The long version of the empty check looks clumsy, but it treats null in another way. Decide what null means, then shorten.

The 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
cleaner decides, remind(person, send_mail) sends. The caller joins them.
Limit
One more name.
Choose when
Deciding and acting change separately.

Grow on a trigger

Write the line down before you need it, for example: an index when a search takes more than 50 ms.

Neighbours

How it fits with other principles

PrincipleRelation
YAGNIYAGNI asks whether to build something now. KISS asks how to build what is needed
DRYA shared helper with many flags is dry and not simple. Two plain functions may be better
Open/closedAn extension point is worth its price when kinds really grow
Separation of concernsMore pieces can be simpler, if they are less tied together
Anti-patternsThe 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.

Sources