KISS: the simplest working solution usually wins
The KISS principle through the delivery fee in Halina's pierogi place: essential vs accidental complexity, signs of over-engineering, refactoring a “clever” rule engine into a single function in C#, TypeScript, Java, Go and Python, and complexity metrics.
The delivery fee in Halina's pierogi place is three sentences in the terms of service: orders from 120 zł ship free, up to 3 km costs 7 zł, and every started kilometre beyond that adds 2 zł; we don't go further than 10 km. In the code, those three sentences turned into a rule engine with priorities, a dictionary of objects and seven types. KISS (Keep It Simple, Stupid) reminds us that a solution should be as complex as the problem, not as complex as its author's ambitions.
- 1986
- the "No Silver Bullet" essay – Fred Brooks splits complexity into essential and accidental
- 10
- cyclomatic complexity threshold – proposed by Thomas McCabe in 1976
- 7 → 1
- types in our example – before and after the refactoring
Where KISS comes from
The acronym is attributed to Kelly Johnson, lead engineer of Lockheed's Skunk Works. An aircraft had to be repairable in the field by an average mechanic with basic tools. In software, that mechanic is the colleague who opens your code at 2 a.m. six months from now because customers cannot place orders.
The second source, more important for programmers, is Fred Brooks's essay No Silver Bullet (1986). Brooks splits the difficulties of building software into essential ones – inherent in the problem itself – and accidental ones – coming from our tools and the way we solve the problem. Essential complexity cannot be removed; at best you can name it well and keep it organised. Accidental complexity can, and should, be kept to a minimum.
| Essential complexity | Accidental complexity | |
|---|---|---|
| Source | terms of service, law, physics, customer expectations | our design decisions and tools |
| In the delivery fee | the 120 zł threshold, 7 zł up to 3 km, rounding kilometres up, the 10 km limit | rule priorities, a string → object dictionary, type casts, the engine |
| What to do with it | name it, test it, keep it in one place | remove it or keep it to a minimum |
The problem: a rule engine for three sentences
The developer who wrote the delivery module expected the rules to multiply. So they built a "flexible" engine: each rule is a class with a priority, data goes into a dictionary, and the engine sorts the rules and folds the result. It works – but read the code as if you had to change the free-delivery threshold for the first time.
Before – delivery fee rule engine
// Before: a "flexible" rule engine for three business rules.
var engine = new FeeEngine([new DistanceFeeRule(7m, 3, 2m), new FreeAboveRule(120m), new MaxDistanceRule(10)]);
Console.WriteLine(engine.Calculate(new FeeContext { ["total"] = 80m, ["km"] = 4.2 })); // 11
// new FeeContext { ["total"] = 80m, ["km"] = 4 } -> InvalidCastException at runtime
public sealed class FeeContext : Dictionary<string, object>; // weakly typed bag
public sealed record FeeResult(decimal Fee, bool Stop = false, bool Rejected = false);
public interface IFeeRule
{
int Priority { get; } // lower runs first; the order lives in magic numbers
FeeResult Apply(FeeContext ctx, FeeResult current);
}
public sealed class MaxDistanceRule(double maxKm) : IFeeRule
{
public int Priority => 0;
public FeeResult Apply(FeeContext ctx, FeeResult current) =>
(double)ctx["km"] > maxKm ? current with { Stop = true, Rejected = true } : current;
}
public sealed class FreeAboveRule(decimal threshold) : IFeeRule
{
public int Priority => 10;
public FeeResult Apply(FeeContext ctx, FeeResult current) =>
(decimal)ctx["total"] >= threshold ? current with { Fee = 0m, Stop = true } : current;
}
public sealed class DistanceFeeRule(decimal baseFee, int includedKm, decimal perKm) : IFeeRule
{
public int Priority => 20;
public FeeResult Apply(FeeContext ctx, FeeResult current)
{
var extraKm = Math.Max(0, (int)Math.Ceiling((double)ctx["km"] - includedKm));
return current with { Fee = baseFee + extraKm * perKm };
}
}
public sealed class FeeEngine(IEnumerable<IFeeRule> rules)
{
private readonly List<IFeeRule> _rules = rules.OrderBy(r => r.Priority).ToList();
public decimal? Calculate(FeeContext ctx)
{
var result = new FeeResult(0m);
foreach (var rule in _rules)
{
result = rule.Apply(ctx, result);
if (result.Stop) break;
}
return result.Rejected ? null : result.Fee;
}
}// Before: a "flexible" rule engine for three business rules.
type FeeContext = Record<string, unknown>; // weakly typed bag
interface FeeResult { fee: number; stop: boolean; rejected?: boolean } // fee in grosze
interface FeeRule {
readonly priority: number; // lower runs first; the order lives in magic numbers
apply(ctx: FeeContext, current: FeeResult): FeeResult;
}
class MaxDistanceRule implements FeeRule {
readonly priority = 0;
constructor(private readonly maxKm: number) {}
apply(ctx: FeeContext, cur: FeeResult): FeeResult {
return (ctx.km as number) > this.maxKm ? { ...cur, stop: true, rejected: true } : cur;
}
}
class FreeAboveRule implements FeeRule {
readonly priority = 10;
constructor(private readonly threshold: number) {}
apply(ctx: FeeContext, cur: FeeResult): FeeResult {
return (ctx.total as number) >= this.threshold ? { ...cur, fee: 0, stop: true } : cur;
}
}
class DistanceFeeRule implements FeeRule {
readonly priority = 20;
constructor(private readonly baseFee: number, private readonly includedKm: number, private readonly perKm: number) {}
apply(ctx: FeeContext, cur: FeeResult): FeeResult {
const extraKm = Math.max(0, Math.ceil((ctx.km as number) - this.includedKm));
return { ...cur, fee: this.baseFee + extraKm * this.perKm };
}
}
class FeeEngine {
private readonly rules: FeeRule[];
constructor(rules: FeeRule[]) {
this.rules = [...rules].sort((a, b) => a.priority - b.priority);
}
calculate(ctx: FeeContext): number | null {
let result: FeeResult = { fee: 0, stop: false };
for (const rule of this.rules) {
result = rule.apply(ctx, result);
if (result.stop) break;
}
return result.rejected ? null : result.fee;
}
}
const engine = new FeeEngine([new DistanceFeeRule(700, 3, 200), new FreeAboveRule(12_000), new MaxDistanceRule(10)]);
console.log(engine.calculate({ total: 8_000, km: 4.2 })); // 1100
console.log(engine.calculate({ total: 8_000, kms: 4.2 })); // typo -> NaN, no errorimport java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
// Before: a "flexible" rule engine for three business rules.
public class FeeEngine {
private final List<FeeRule> rules;
FeeEngine(List<FeeRule> rules) {
this.rules = rules.stream().sorted(Comparator.comparingInt(FeeRule::priority)).toList();
}
Optional<BigDecimal> calculate(Map<String, Object> ctx) { // weakly typed bag
var result = new FeeResult();
for (var rule : rules) {
rule.apply(ctx, result);
if (result.stop) break;
}
return result.rejected ? Optional.empty() : Optional.of(result.fee);
}
public static void main(String[] args) {
var engine = new FeeEngine(List.of(
new DistanceFeeRule(new BigDecimal("7"), 3, new BigDecimal("2")),
new FreeAboveRule(new BigDecimal("120")),
new MaxDistanceRule(10)));
System.out.println(engine.calculate(Map.of("total", new BigDecimal("80"), "km", 4.2))); // Optional[11]
// Map.of("total", 80, "km", 4.2) -> ClassCastException at runtime
}
}
class FeeResult {
BigDecimal fee = BigDecimal.ZERO;
boolean stop, rejected;
}
interface FeeRule {
int priority(); // lower runs first; the order lives in magic numbers
void apply(Map<String, Object> ctx, FeeResult result);
}
record MaxDistanceRule(double maxKm) implements FeeRule {
public int priority() { return 0; }
public void apply(Map<String, Object> ctx, FeeResult r) {
if ((double) ctx.get("km") > maxKm) { r.stop = true; r.rejected = true; }
}
}
record FreeAboveRule(BigDecimal threshold) implements FeeRule {
public int priority() { return 10; }
public void apply(Map<String, Object> ctx, FeeResult r) {
if (((BigDecimal) ctx.get("total")).compareTo(threshold) >= 0) { r.fee = BigDecimal.ZERO; r.stop = true; }
}
}
record DistanceFeeRule(BigDecimal baseFee, int includedKm, BigDecimal perKm) implements FeeRule {
public int priority() { return 20; }
public void apply(Map<String, Object> ctx, FeeResult r) {
int extraKm = Math.max(0, (int) Math.ceil((double) ctx.get("km") - includedKm));
r.fee = baseFee.add(perKm.multiply(BigDecimal.valueOf(extraKm)));
}
}package main
import (
"fmt"
"math"
"sort"
)
// Before: a "flexible" rule engine for three business rules.
type FeeContext map[string]any // weakly typed bag
type FeeResult struct {
Fee int64 // grosze
Stop bool
Rejected bool
}
type FeeRule interface {
Priority() int // lower runs first; the order lives in magic numbers
Apply(ctx FeeContext, cur FeeResult) FeeResult
}
type MaxDistanceRule struct{ MaxKm float64 }
func (MaxDistanceRule) Priority() int { return 0 }
func (r MaxDistanceRule) Apply(ctx FeeContext, cur FeeResult) FeeResult {
if ctx["km"].(float64) > r.MaxKm { // panics if someone passes an int
cur.Stop, cur.Rejected = true, true
}
return cur
}
type FreeAboveRule struct{ Threshold int64 }
func (FreeAboveRule) Priority() int { return 10 }
func (r FreeAboveRule) Apply(ctx FeeContext, cur FeeResult) FeeResult {
if ctx["total"].(int64) >= r.Threshold {
cur.Fee, cur.Stop = 0, true
}
return cur
}
type DistanceFeeRule struct {
BaseFee, PerKm int64
IncludedKm float64
}
func (DistanceFeeRule) Priority() int { return 20 }
func (r DistanceFeeRule) Apply(ctx FeeContext, cur FeeResult) FeeResult {
extraKm := math.Max(0, math.Ceil(ctx["km"].(float64)-r.IncludedKm))
cur.Fee = r.BaseFee + int64(extraKm)*r.PerKm
return cur
}
type FeeEngine struct{ rules []FeeRule }
func NewFeeEngine(rules ...FeeRule) *FeeEngine {
sort.Slice(rules, func(i, j int) bool { return rules[i].Priority() < rules[j].Priority() })
return &FeeEngine{rules: rules}
}
func (e *FeeEngine) Calculate(ctx FeeContext) (fee int64, ok bool) {
var res FeeResult
for _, rule := range e.rules {
if res = rule.Apply(ctx, res); res.Stop {
break
}
}
return res.Fee, !res.Rejected
}
func main() {
engine := NewFeeEngine(DistanceFeeRule{BaseFee: 700, PerKm: 200, IncludedKm: 3}, FreeAboveRule{12000}, MaxDistanceRule{10})
fmt.Println(engine.Calculate(FeeContext{"total": int64(8000), "km": 4.2})) // 1100 true
}import math
from dataclasses import dataclass, replace
from decimal import Decimal
from typing import Any, Protocol
# Before: a "flexible" rule engine for three business rules.
FeeContext = dict[str, Any] # weakly typed bag
@dataclass(frozen=True)
class FeeResult:
fee: Decimal = Decimal("0")
stop: bool = False
rejected: bool = False
class FeeRule(Protocol):
priority: int # lower runs first; the order lives in magic numbers
def apply(self, ctx: FeeContext, current: FeeResult) -> FeeResult: ...
@dataclass
class MaxDistanceRule:
max_km: float
priority: int = 0
def apply(self, ctx: FeeContext, current: FeeResult) -> FeeResult:
return replace(current, stop=True, rejected=True) if ctx["km"] > self.max_km else current
@dataclass
class FreeAboveRule:
threshold: Decimal
priority: int = 10
def apply(self, ctx: FeeContext, current: FeeResult) -> FeeResult:
return replace(current, fee=Decimal("0"), stop=True) if ctx["total"] >= self.threshold else current
@dataclass
class DistanceFeeRule:
base_fee: Decimal
included_km: int
per_km: Decimal
priority: int = 20
def apply(self, ctx: FeeContext, current: FeeResult) -> FeeResult:
extra_km = max(0, math.ceil(ctx["km"] - self.included_km))
return replace(current, fee=self.base_fee + extra_km * self.per_km)
class FeeEngine:
def __init__(self, rules: list[FeeRule]) -> None:
self._rules = sorted(rules, key=lambda r: r.priority)
def calculate(self, ctx: FeeContext) -> Decimal | None:
result = FeeResult()
for rule in self._rules:
result = rule.apply(ctx, result)
if result.stop:
break
return None if result.rejected else result.fee
engine = FeeEngine([DistanceFeeRule(Decimal("7"), 3, Decimal("2")), FreeAboveRule(Decimal("120")), MaxDistanceRule(10)])
print(engine.calculate({"total": Decimal("80"), "km": 4.2})) # 11What is wrong, if every class on its own is short?
- Rule order hidden in numbers. To know that the 10 km limit is checked before free delivery, you have to compare
Priorityacross three files. - Weak typing. A
string → objectdictionary switches the compiler off. A typo likekmsin TypeScript yieldsNaNinstead of an error, and in C#, Java and Go an integer where a float was expected ends in an exception (or apanic) only in the running application. - Flexibility nobody uses. In two years the rules changed once – the threshold went from 100 to 120 zł. The engine was meant to make adding rules easy; instead it makes it harder to change the only number that ever changes.
- The tests test the engine, not the rules. Half of them check sorting and the
Stopflag, not what a customer on Długa Street will pay.
Refactoring: from clever to simple
The simple version writes the rules down exactly as they read: first the distance limit, then free delivery, finally the per-kilometre fee. Constants have names, the compiler checks the types, and the order of the conditions is the order of reading.
After – the delivery fee as one function
Console.WriteLine(Show(Delivery.Fee(orderTotal: 80m, distanceKm: 4.2))); // 11
Console.WriteLine(Show(Delivery.Fee(orderTotal: 150m, distanceKm: 4.2))); // 0
Console.WriteLine(Show(Delivery.Fee(orderTotal: 80m, distanceKm: 12))); // no delivery
static string Show(decimal? fee) => fee?.ToString() ?? "no delivery";
public static class Delivery
{
public const double MaxDistanceKm = 10;
public const decimal FreeFrom = 120m;
public const decimal BaseFee = 7m; // covers the first 3 km
public const int IncludedKm = 3;
public const decimal PerExtraKm = 2m; // for every started kilometre above that
/// <summary>Returns null when the address is outside the delivery area.</summary>
public static decimal? Fee(decimal orderTotal, double distanceKm)
{
if (distanceKm > MaxDistanceKm) return null;
if (orderTotal >= FreeFrom) return 0m;
var extraKm = Math.Max(0, (int)Math.Ceiling(distanceKm - IncludedKm));
return BaseFee + extraKm * PerExtraKm;
}
}// Amounts in grosze (integers): no floating-point surprises with money.
export const MAX_DISTANCE_KM = 10;
export const FREE_FROM = 12_000;
export const BASE_FEE = 700; // covers the first 3 km
export const INCLUDED_KM = 3;
export const PER_EXTRA_KM = 200; // for every started kilometre above that
/** Returns null when the address is outside the delivery area. */
export function deliveryFee(orderTotal: number, distanceKm: number): number | null {
if (distanceKm > MAX_DISTANCE_KM) return null;
if (orderTotal >= FREE_FROM) return 0;
const extraKm = Math.max(0, Math.ceil(distanceKm - INCLUDED_KM));
return BASE_FEE + extraKm * PER_EXTRA_KM;
}
console.log(deliveryFee(8_000, 4.2)); // 1100
console.log(deliveryFee(15_000, 4.2)); // 0
console.log(deliveryFee(8_000, 12)); // nullimport java.math.BigDecimal;
import java.util.Optional;
public final class Delivery {
static final double MAX_DISTANCE_KM = 10;
static final BigDecimal FREE_FROM = new BigDecimal("120");
static final BigDecimal BASE_FEE = new BigDecimal("7"); // covers the first 3 km
static final int INCLUDED_KM = 3;
static final BigDecimal PER_EXTRA_KM = new BigDecimal("2"); // for every started kilometre above that
private Delivery() {}
/** Empty when the address is outside the delivery area. */
static Optional<BigDecimal> fee(BigDecimal orderTotal, double distanceKm) {
if (distanceKm > MAX_DISTANCE_KM) return Optional.empty();
if (orderTotal.compareTo(FREE_FROM) >= 0) return Optional.of(BigDecimal.ZERO);
int extraKm = Math.max(0, (int) Math.ceil(distanceKm - INCLUDED_KM));
return Optional.of(BASE_FEE.add(PER_EXTRA_KM.multiply(BigDecimal.valueOf(extraKm))));
}
public static void main(String[] args) {
System.out.println(fee(new BigDecimal("80"), 4.2)); // Optional[11]
System.out.println(fee(new BigDecimal("150"), 4.2)); // Optional[0]
System.out.println(fee(new BigDecimal("80"), 12)); // Optional.empty
}
}package main
import (
"fmt"
"math"
)
// Amounts in grosze (integers): no floating-point surprises with money.
const (
MaxDistanceKm = 10.0
FreeFrom = 12000
BaseFee = 700 // covers the first 3 km
IncludedKm = 3.0
PerExtraKm = 200 // for every started kilometre above that
)
// DeliveryFee returns ok == false when the address is outside the delivery area.
func DeliveryFee(orderTotal int64, distanceKm float64) (fee int64, ok bool) {
if distanceKm > MaxDistanceKm {
return 0, false
}
if orderTotal >= FreeFrom {
return 0, true
}
extraKm := int64(math.Max(0, math.Ceil(distanceKm-IncludedKm)))
return BaseFee + extraKm*PerExtraKm, true
}
func main() {
fmt.Println(DeliveryFee(8000, 4.2)) // 1100 true
fmt.Println(DeliveryFee(15000, 4.2)) // 0 true
fmt.Println(DeliveryFee(8000, 12)) // 0 false
}import math
from decimal import Decimal
MAX_DISTANCE_KM = 10
FREE_FROM = Decimal("120")
BASE_FEE = Decimal("7") # covers the first 3 km
INCLUDED_KM = 3
PER_EXTRA_KM = Decimal("2") # for every started kilometre above that
def delivery_fee(order_total: Decimal, distance_km: float) -> Decimal | None:
"""Return the delivery fee, or None when the address is outside the delivery area."""
if distance_km > MAX_DISTANCE_KM:
return None
if order_total >= FREE_FROM:
return Decimal("0")
extra_km = max(0, math.ceil(distance_km - INCLUDED_KM))
return BASE_FEE + extra_km * PER_EXTRA_KM
print(delivery_fee(Decimal("80"), 4.2)) # 11
print(delivery_fee(Decimal("150"), 4.2)) # 0
print(delivery_fee(Decimal("80"), 12)) # NoneNote two details that are not accidental complexity: rounding kilometres up (Ceiling, ceil) and the type of the amount. In C#, Java and Python we use decimal types (decimal, BigDecimal, Decimal); in TypeScript and Go, integers in grosze. Those are requirements of money, not decoration.
- Step 1 Write the rule as sentences – The three sentences from the terms of service are the specification. If you cannot compare the code with them line by line, something is too much.
- Step 2 Pin the behaviour with tests – Before you delete anything, record the cases: 80 zł and 4.2 km → 11 zł, 150 zł → 0 zł, 12 km → no delivery, exactly 3 km → 7 zł.
- Step 3 Inline the abstractions – Move the body of every rule into one function, in priority order. Replace the dictionary with typed parameters.
- Step 4 Delete what is dead – The interface, the engine, the result record and rule registration no longer have users – remove them together with their tests.
- Step 5 Name the constants – The threshold, the base fee and the limit get names. When the terms change, you change one line.
How to measure complexity
Cyclomatic complexity, proposed by Thomas McCabe in 1976, is the number of independent paths through a function. In practice you count decision points (if, a loop, case, &&, ||, the ?: operator) and add one. The Fee function has two ifs, so its complexity is 3 – and three test cases are enough to walk every path.
The catch: cyclomatic complexity looks at one function. Over-engineered code often has short methods with a complexity of 1–2, while the real difficulty sits between them – in the number of types, the indirection layers and the implicit ordering. That is why it pays to look at several measures at once.
| Before (rule engine) | After (one function) | |
|---|---|---|
| Types (classes, interfaces, records) | 7 | 1 |
| Total cyclomatic complexity | 13 | 3 |
| Highest complexity of a single method | 4 | 3 |
| Files to open to understand the rule | 7 | 1 |
The chart shows why method-level cyclomatic complexity is not enough: the most complex method "before" scores 4, "after" scores 3. The difference only shows up in the total and in the number of types. A useful complement is cognitive complexity, developed by SonarSource. It penalises nesting and breaks in the flow (break, continue, recursion) – what tires a reader, not just the number of paths to test.
Simple, not simplistic
Simplicity is not about throwing away whatever is inconvenient. A simplistic solution is shorter because it skips part of the problem – and that part comes back as a production bug:
// Simplistic: shorter, but it quietly drops two business rules and uses floats for money.
const fee = (total: number, km: number) => (total >= 120 ? 0 : 7 + (km - 3) * 2);
fee(80, 4.2); // 9.4 – no rounding up, and 12 km would happily cost 25
fee(80, 1); // 3 – below the base fee, because nobody handled km < 3Other "simplifications" that are really bugs:
- amounts in
floatordoubleinstead of a decimal type or integer grosze; - dates without a time zone ("everyone is in Poland anyway" – until the first clock change, when orders placed at 2:30 a.m. vanish from the report);
- payments without idempotency or retries ("the network works, doesn't it?");
- global state instead of a passed-in dependency – fewer parameters, but tests start depending on each other.
A good test of simplicity: you can explain the code in two minutes without saying "but". Simplistic code can be explained quickly too – and then someone from the business asks: "what about delivery at 12 km?".
Signs of over-engineering
- An interface with a single implementation that you do not replace even in tests.
- Configuration and parameters "just in case" that nobody has ever changed.
- A home-grown mini-framework:
Engine,Manager,Processor,Registryin names, reflection, registration through annotations. string → objectdictionaries,map[string]anyor**kwargspassed through several layers.- Pass-through methods: a layer that only calls the next one with the same arguments.
- To understand one business rule you open five files.
- Tests have more mocks than assertions.
- "Clever" one-liners: nested
?:operators, regular expressions for everything, bit tricks instead of readable conditions.
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
When to use it and when to be careful
When to apply
- always as the default direction: start with the simplest solution that passes the tests
- in code review – ask "what would break if we deleted this?"
- when a business rule fits in a few sentences – let the code fit in them too
- in code read by many people: internal libraries, modules on team boundaries
When to be careful
- when "simplicity" means skipping requirements: money, time zones, security
- when the problem really is complex (e.g. a price list with hundreds of rules edited by the sales team) – then the structure is essential complexity
- as an argument against every abstraction – a third copy of the same logic is complexity too
- as an excuse for "clever" shortcuts: shorter code is not always simpler
In practice: tools and code review
| Ecosystem | Tool | What it gives you |
|---|---|---|
| .NET | rule CA1502 from the .NET analyzers, code metrics in Visual Studio | method cyclomatic complexity, maintainability index |
| Java | Checkstyle CyclomaticComplexity, PMD, SonarQube | complexity thresholds in CI, cognitive complexity |
| TypeScript / JS | ESLint: the complexity rule, sonarjs/cognitive-complexity | a per-function complexity limit, warnings in the editor |
| Go | gocyclo, gocognit, cyclop in golangci-lint | function and package complexity |
| Python | radon cc, flake8 with --max-complexity (C901), ruff C901 | functions ranked A to F, a threshold in CI |
Code review tips:
- Ask what problem an abstraction solves today – not whether it might come in handy some day.
- Ask for a usage example. An abstraction with a single client can usually be inlined.
- Treat tool thresholds as a conversation starter, not a verdict. A
switchwith twelve one-line cases can be simpler than twelve classes. - Look at names:
GenericProcessorFactoryManagersays more about the architecture than about the problem.
"Simple Made Easy" - Rich Hickey (2011) (youtube)
Related principles
KISS rarely works alone. YAGNI tells you what not to build now – and is the most effective way to stay simple. DRY can pull against KISS: removing duplication adds an abstraction, and a wrong abstraction is accidental complexity. SOLID gives you tools to organise essential complexity, but applied mechanically (an interface for every class) it becomes a source of complexity itself. Even Strategy only makes sense when there are several variants that really change – for a single fee formula, a function is enough.
YAGNI – Don't build features in advance – the shortest road to simple code
DRY – One source of knowledge – and when duplication is cheaper than an abstraction
SOLID – Five principles for organising the complexity you actually need
Test yourself
Question: Which part of the delivery module is essential complexity?
- The rule priorities in the engine
- Rounding started kilometres up
- The `string → object` dictionary passed to the rules
- The `IFeeRule` interface
Interview question: what is the difference between simple and easy code?
Rich Hickey popularised the distinction in his talk Simple Made Easy (2011). Simple is an objective property: few intertwined parts, each doing one thing and understandable on its own. Easy is subjective: close to what we already know – a favourite framework, a ready-made generator, a copy from the previous project. An easy solution can be complex (an ORM with magic that hides the queries), while a simple one can be harder at first (passing dependencies explicitly instead of using global state). A good answer gives an example from your own project and notes that simplicity pays off during maintenance, while ease pays off when you first write the code.