KISS — Keep It Simple, Stupid
Introduction
Two developers are asked for a function that checks whether a number is even. One writes number % 2 == 0. The other, wanting to show what they can do, writes a recursive bit trick with a cache. Both give the right answer. Any teammate can check the first in a glance; the second takes real effort to trust. The second solution is worse, because its extra machinery buys nothing.
KISS stands for keep it simple, stupid. The phrase is linked with Kelly Johnson, the engineer who led Lockheed's Skunk Works, the team behind aircraft such as the SR-71 Blackbird; Lockheed Martin's own history of him calls it his favourite maxim. In software it means choosing the simplest design that meets the requirements you actually have, and adding structure when a real need for it arrives.
The picture shows one small requirement built two ways:

Why Simplicity Matters
Most of the work on a program comes after it is first written. Robert Glass's figure, quoted in Why LLD Matters — The 70% Maintenance Problem, is that "Maintenance typically consumes 40 to 80 percent (average 60 percent) of software costs." Every layer, every interface and every pattern in a design is something the next person has to read through before they can change anything. When a layer does nothing useful, that reading is wasted, bugs have more places to hide, and people start working around code they do not trust instead of fixing it.
Tony Hoare put the choice well in his 1980 Turing Award lecture: "One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." He added: "The first method is far more difficult." Simple code is often the harder thing to write, because it takes a clear understanding of the problem to find the direct way through it.
An Over-Built Calculator
The requirement is small: add up the prices in a cart and take a percentage off. Here it is built with a strategy interface, two discounts, a factory and an engine.
from typing import Protocol
# The requirement: a cart's total with a percentage discount. This version builds a
# strategy, a factory and an engine for it, though only one kind of discount exists.
class DiscountStrategy(Protocol):
def apply(self, total_cents: int) -> int: ...
class PercentageDiscount:
def __init__(self, percent: int) -> None:
self._percent = percent
def apply(self, total_cents: int) -> int:
return total_cents * (100 - self._percent) // 100
class NoDiscount:
def apply(self, total_cents: int) -> int:
return total_cents
class DiscountFactory:
@staticmethod
def create(discount_type: str, value: int) -> DiscountStrategy:
if discount_type == "percentage":
return PercentageDiscount(value)
return NoDiscount()
class PricingEngine:
def __init__(self, strategy: DiscountStrategy) -> None:
self._strategy = strategy
def calculate(self, prices_cents: list[int]) -> int:
subtotal = sum(prices_cents)
return self._strategy.apply(subtotal)
# Whole cents as dollars and cents, the same in every locale
def dollars(cents: int) -> str:
return f"{cents // 100}.{cents % 100:02d}"
def main() -> None:
strategy = DiscountFactory.create("percentage", 10)
engine = PricingEngine(strategy)
total = engine.calculate([2999, 999, 4999])
print(f"Total: ${dollars(total)}")
if __name__ == "__main__":
main()import java.util.List;
// The requirement: a cart's total with a percentage discount. This version builds a
// strategy, a factory and an engine for it, though only one kind of discount exists.
interface DiscountStrategy {
int apply(int totalCents);
}
class PercentageDiscount implements DiscountStrategy {
private final int percent;
PercentageDiscount(int percent) {
this.percent = percent;
}
public int apply(int totalCents) {
return totalCents * (100 - percent) / 100;
}
}
class NoDiscount implements DiscountStrategy {
public int apply(int totalCents) {
return totalCents;
}
}
class DiscountFactory {
static DiscountStrategy create(String discountType, int value) {
if (discountType.equals("percentage")) {
return new PercentageDiscount(value);
}
return new NoDiscount();
}
}
class PricingEngine {
private final DiscountStrategy strategy;
PricingEngine(DiscountStrategy strategy) {
this.strategy = strategy;
}
int calculate(List<Integer> pricesCents) {
int subtotal = 0;
for (int price : pricesCents) {
subtotal += price;
}
return strategy.apply(subtotal);
}
}
public class Checkout {
// Whole cents as dollars and cents, the same in every locale
static String dollars(int cents) {
int rest = cents % 100;
return cents / 100 + "." + (rest < 10 ? "0" : "") + rest;
}
public static void main(String[] args) {
DiscountStrategy strategy = DiscountFactory.create("percentage", 10);
PricingEngine engine = new PricingEngine(strategy);
int total = engine.calculate(List.of(2999, 999, 4999));
System.out.println("Total: $" + dollars(total));
}
}#include <iostream>
#include <memory>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
// The requirement: a cart's total with a percentage discount. This version builds a
// strategy, a factory and an engine for it, though only one kind of discount exists.
class DiscountStrategy {
public:
virtual ~DiscountStrategy() = default;
virtual int apply(int totalCents) const = 0;
};
class PercentageDiscount : public DiscountStrategy {
public:
explicit PercentageDiscount(int percent) : percent(percent) {}
int apply(int totalCents) const override {
return totalCents * (100 - percent) / 100;
}
private:
int percent;
};
class NoDiscount : public DiscountStrategy {
public:
int apply(int totalCents) const override { return totalCents; }
};
class DiscountFactory {
public:
static std::unique_ptr<DiscountStrategy> create(const std::string& discountType,
int value) {
if (discountType == "percentage") {
return std::make_unique<PercentageDiscount>(value);
}
return std::make_unique<NoDiscount>();
}
};
class PricingEngine {
public:
explicit PricingEngine(std::unique_ptr<DiscountStrategy> strategy)
: strategy(std::move(strategy)) {}
int calculate(const std::vector<int>& pricesCents) const {
int subtotal = std::accumulate(pricesCents.begin(), pricesCents.end(), 0);
return strategy->apply(subtotal);
}
private:
std::unique_ptr<DiscountStrategy> strategy;
};
// Whole cents as dollars and cents, the same in every locale
std::string dollars(int cents) {
int rest = cents % 100;
return std::to_string(cents / 100) + "." + (rest < 10 ? "0" : "") +
std::to_string(rest);
}
int main() {
std::unique_ptr<DiscountStrategy> strategy =
DiscountFactory::create("percentage", 10);
PricingEngine engine(std::move(strategy));
int total = engine.calculate({2999, 999, 4999});
std::cout << "Total: $" << dollars(total) << "\n";
return 0;
}// The requirement: a cart's total with a percentage discount. This version builds a
// strategy, a factory and an engine for it, though only one kind of discount exists.
interface DiscountStrategy {
apply(totalCents: number): number;
}
class PercentageDiscount implements DiscountStrategy {
constructor(private readonly percent: number) {}
apply(totalCents: number): number {
return Math.floor((totalCents * (100 - this.percent)) / 100);
}
}
class NoDiscount implements DiscountStrategy {
apply(totalCents: number): number {
return totalCents;
}
}
class DiscountFactory {
static create(discountType: string, value: number): DiscountStrategy {
if (discountType === "percentage") {
return new PercentageDiscount(value);
}
return new NoDiscount();
}
}
class PricingEngine {
constructor(private readonly strategy: DiscountStrategy) {}
calculate(pricesCents: number[]): number {
const subtotal = pricesCents.reduce((sum, price) => sum + price, 0);
return this.strategy.apply(subtotal);
}
}
// Whole cents as dollars and cents, the same in every locale
function dollars(cents: number): string {
const rest = cents % 100;
return `${Math.floor(cents / 100)}.${rest < 10 ? "0" : ""}${rest}`;
}
function main(): void {
const strategy = DiscountFactory.create("percentage", 10);
const engine = new PricingEngine(strategy);
const total = engine.calculate([2999, 999, 4999]);
console.log(`Total: $${dollars(total)}`);
}
main();using System;
using System.Collections.Generic;
using System.Linq;
// The requirement: a cart's total with a percentage discount. This version builds a
// strategy, a factory and an engine for it, though only one kind of discount exists.
public interface IDiscountStrategy
{
int Apply(int totalCents);
}
public class PercentageDiscount : IDiscountStrategy
{
private readonly int percent;
public PercentageDiscount(int percent)
{
this.percent = percent;
}
public int Apply(int totalCents)
{
return totalCents * (100 - percent) / 100;
}
}
public class NoDiscount : IDiscountStrategy
{
public int Apply(int totalCents)
{
return totalCents;
}
}
public static class DiscountFactory
{
public static IDiscountStrategy Create(string discountType, int value)
{
if (discountType == "percentage")
{
return new PercentageDiscount(value);
}
return new NoDiscount();
}
}
public class PricingEngine
{
private readonly IDiscountStrategy strategy;
public PricingEngine(IDiscountStrategy strategy)
{
this.strategy = strategy;
}
public int Calculate(List<int> pricesCents)
{
int subtotal = pricesCents.Sum();
return strategy.Apply(subtotal);
}
}
public class Checkout
{
// Whole cents as dollars and cents, the same in every locale
static string Dollars(int cents)
{
int rest = cents % 100;
return (cents / 100) + "." + (rest < 10 ? "0" : "") + rest;
}
public static void Main(string[] args)
{
IDiscountStrategy strategy = DiscountFactory.Create("percentage", 10);
PricingEngine engine = new PricingEngine(strategy);
int total = engine.Calculate(new List<int> { 2999, 999, 4999 });
Console.WriteLine("Total: $" + Dollars(total));
}
}package main
import "fmt"
// The requirement: a cart's total with a percentage discount. This version builds a
// strategy, a factory and an engine for it, though only one kind of discount exists.
// DiscountStrategy takes a discount off a total.
type DiscountStrategy interface {
Apply(totalCents int) int
}
// PercentageDiscount takes a percentage off.
type PercentageDiscount struct {
percent int
}
// Apply takes the percentage off the total.
func (d PercentageDiscount) Apply(totalCents int) int {
return totalCents * (100 - d.percent) / 100
}
// NoDiscount leaves the total as it is.
type NoDiscount struct{}
// Apply gives the total back.
func (NoDiscount) Apply(totalCents int) int {
return totalCents
}
// DiscountFactory makes a discount from its type's name.
type DiscountFactory struct{}
// Create makes the discount the type names, or none.
func (DiscountFactory) Create(discountType string, value int) DiscountStrategy {
if discountType == "percentage" {
return PercentageDiscount{percent: value}
}
return NoDiscount{}
}
// PricingEngine adds the prices and hands the subtotal to its discount.
type PricingEngine struct {
strategy DiscountStrategy
}
// NewPricingEngine makes a PricingEngine with the discount it is given.
func NewPricingEngine(strategy DiscountStrategy) PricingEngine {
return PricingEngine{strategy: strategy}
}
// Calculate works out the total.
func (e PricingEngine) Calculate(pricesCents []int) int {
subtotal := 0
for _, price := range pricesCents {
subtotal += price
}
return e.strategy.Apply(subtotal)
}
// dollars writes whole cents as dollars and cents, the same in every locale.
func dollars(cents int) string {
return fmt.Sprintf("%d.%02d", cents/100, cents%100)
}
func main() {
strategy := DiscountFactory{}.Create("percentage", 10)
engine := NewPricingEngine(strategy)
total := engine.Calculate([]int{2999, 999, 4999})
fmt.Printf("Total: $%s\n", dollars(total))
}It prints:
Total: $80.97
To get one total, the program uses one interface and four classes, makes two objects and goes through three calls: the factory's create, the engine's calculate, and the discount's apply. NoDiscount is never used at all, because there is only one kind of discount. Nothing in the requirement asks for any of this. The interface and the factory are there for discounts that may never come.
The Direct Solution
Here is the same requirement met directly, with one function.
# The same requirement, met directly: one function adds the prices and takes the
# percentage off.
def calculate_total(prices_cents: list[int], discount_percent: int) -> int:
subtotal = sum(prices_cents)
return subtotal * (100 - discount_percent) // 100
# Whole cents as dollars and cents, the same in every locale
def dollars(cents: int) -> str:
return f"{cents // 100}.{cents % 100:02d}"
def main() -> None:
total = calculate_total([2999, 999, 4999], 10)
print(f"Total: ${dollars(total)}")
if __name__ == "__main__":
main()import java.util.List;
// The same requirement, met directly: one function adds the prices and takes the
// percentage off.
public class Checkout {
static int calculateTotal(List<Integer> pricesCents, int discountPercent) {
int subtotal = 0;
for (int price : pricesCents) {
subtotal += price;
}
return subtotal * (100 - discountPercent) / 100;
}
// Whole cents as dollars and cents, the same in every locale
static String dollars(int cents) {
int rest = cents % 100;
return cents / 100 + "." + (rest < 10 ? "0" : "") + rest;
}
public static void main(String[] args) {
int total = calculateTotal(List.of(2999, 999, 4999), 10);
System.out.println("Total: $" + dollars(total));
}
}#include <iostream>
#include <numeric>
#include <string>
#include <vector>
// The same requirement, met directly: one function adds the prices and takes the
// percentage off.
int calculateTotal(const std::vector<int>& pricesCents, int discountPercent) {
int subtotal = std::accumulate(pricesCents.begin(), pricesCents.end(), 0);
return subtotal * (100 - discountPercent) / 100;
}
// Whole cents as dollars and cents, the same in every locale
std::string dollars(int cents) {
int rest = cents % 100;
return std::to_string(cents / 100) + "." + (rest < 10 ? "0" : "") +
std::to_string(rest);
}
int main() {
int total = calculateTotal({2999, 999, 4999}, 10);
std::cout << "Total: $" << dollars(total) << "\n";
return 0;
}// The same requirement, met directly: one function adds the prices and takes the
// percentage off.
function calculateTotal(pricesCents: number[], discountPercent: number): number {
const subtotal = pricesCents.reduce((sum, price) => sum + price, 0);
return Math.floor((subtotal * (100 - discountPercent)) / 100);
}
// Whole cents as dollars and cents, the same in every locale
function dollars(cents: number): string {
const rest = cents % 100;
return `${Math.floor(cents / 100)}.${rest < 10 ? "0" : ""}${rest}`;
}
function main(): void {
const total = calculateTotal([2999, 999, 4999], 10);
console.log(`Total: $${dollars(total)}`);
}
main();using System;
using System.Collections.Generic;
using System.Linq;
// The same requirement, met directly: one function adds the prices and takes the
// percentage off.
public class Checkout
{
static int CalculateTotal(List<int> pricesCents, int discountPercent)
{
int subtotal = pricesCents.Sum();
return subtotal * (100 - discountPercent) / 100;
}
// Whole cents as dollars and cents, the same in every locale
static string Dollars(int cents)
{
int rest = cents % 100;
return (cents / 100) + "." + (rest < 10 ? "0" : "") + rest;
}
public static void Main(string[] args)
{
int total = CalculateTotal(new List<int> { 2999, 999, 4999 }, 10);
Console.WriteLine("Total: $" + Dollars(total));
}
}package main
import "fmt"
// The same requirement, met directly: one function adds the prices and takes the
// percentage off.
func calculateTotal(pricesCents []int, discountPercent int) int {
subtotal := 0
for _, price := range pricesCents {
subtotal += price
}
return subtotal * (100 - discountPercent) / 100
}
// dollars writes whole cents as dollars and cents, the same in every locale.
func dollars(cents int) string {
return fmt.Sprintf("%d.%02d", cents/100, cents%100)
}
func main() {
total := calculateTotal([]int{2999, 999, 4999}, 10)
fmt.Printf("Total: $%s\n", dollars(total))
}It prints:
Total: $80.97
The same total, from one function and one call. Anyone can read it in a moment, and testing it is one call with a list and a number. It is also easy to change. If the shop later adds a second kind of discount, say a flat amount off, that is the moment for a DiscountStrategy interface with PercentageDiscount and FlatDiscount behind it, which Strategy Pattern — Swappable Algorithms describes. The pattern is a good tool; it earns its place when there are real variants to choose between.
Signs of Needless Complexity
A few signs show that a design is more complicated than its problem.
An interface for one class. An interface PaymentProcessor, a factory PaymentProcessorFactory, and exactly one class behind them, StripePaymentProcessor. Use the class directly, and bring in the interface when a second processor really arrives.
A pass-through layer. Method a calls b, which calls c, and b adds nothing: no check, no change, no decision. Every such layer is one more place to read on the way to the code that does the work.
Settings for later. A function takes twelve parameters so it can handle every case anyone might imagine, and the code calls it in two ways. Two small functions, one for each way, are easier to read and to test.
Clever code. Nested ternaries, bit tricks or dense one-liners that save a few lines and cost every reader time. If a careful teammate cannot see quickly what a line does, it is too clever.
Patterns for show. Observer, Strategy and Command in a short script with no problem for them to solve. Patterns are answers to recurring design problems; added without the problem, they are only weight.
Common Mistakes
Simple turned into sloppy. Putting everything into one long function with no structure is not simplicity. A function with a clear name, one job and an easy order to follow is simpler to understand than a wall of code, even when it takes a few more lines. The goal is code that is easy to understand.
Refusing a pattern the problem needs. When the problem really has many interchangeable behaviours, such as several payment methods, a strategy can be the simpler design: a long if chain over every case is harder to read and to change. KISS argues against adding a pattern before its problem exists, and in favour of it once the problem is here.
Skipping error handling. Handling failures that will really happen, such as a database that is down, is part of the requirement. KISS asks you not to over-build the solution; the problem itself still has to be handled in full.
KISS and the Other Principles
KISS sometimes pulls against the other principles, and the trade-off is worth thinking through each time.
With DRY. DRY — Don't Repeat Yourself asks for one home for each piece of knowledge. Sometimes the shared version becomes a complicated utility that is harder to follow than the two copies it replaced. When the shared version costs more than the copies, keep the copies.
With open/closed. O — Open/Closed Principle adds new behaviour as new classes behind an interface. Building those extension points for changes that may never come is exactly the over-building KISS warns about, and Martin himself writes that "Since closure cannot be complete, it must be strategic." Add the extension point when the second variation actually appears.
With splitting classes. Breaking a short class with one clear purpose into three tiny classes with interfaces between them can make it harder to follow. If the class already does one job and reads easily, it is well designed.
One question helps in every case: does this complexity solve a problem I have now, or one I only imagine having later? YAGNI — You Aren't Gonna Need It comes next and takes that question further.
Key Takeaways
- KISS means choosing the simplest design that meets today's real requirements, and adding structure when a real need for it arrives.
- Every needless layer, interface or pattern is something the next reader has to get through before they can change anything.
- A pattern earns its place when there are real variants to choose between; before that, a direct function is easier to read, test and change.
- Keeping it simple never means sloppy structure, or skipping the failures the problem really has.