Last week I reviewed a PR for a simple feature: add a discount code field to checkout. The PR had 47 files changed—a DiscountStrategyFactory, a DiscountValidationService, three interfaces.
Two weeks of work. Should have been two days.
Every codebase I've inherited has layers of abstraction solving problems nobody has.
Repository patterns wrapping ORMs. Message queues for services on the same machine. Microservices for a team of three.
The best engineers I've worked with don't write sophisticated code. They write the simplest thing that works, then add complexity when reality forces it.
I worked on a payments system with a plugin architecture for providers.
Theory:
Add new providers easily!
Just implement the interface!
Reality:
Provider A needs retry logic
Provider B needs different error codes
Provider C needs async webhooks
Every provider is a special case.
We ripped it out. Provider-specific code. Easier to understand, same speed to add new ones.
Red flags:
Start stupid simple. Embarrassingly simple.
Wait for pain. When you're duplicating code in three places, when changes break unrelated things—that's when you refactor. Not before.
Optimize for deletion. Write code that's easy to throw away.
Junior: Writes simple code (doesn't know patterns)
Mid: Writes complex code (knows patterns, wants to use them)
Senior: Writes simple code (knows patterns, knows when not to)
Skip the middle phase. Learn from other people's post-mortems instead of creating your own.
The best code is the simplest code that solves the actual problem.
— blanho
Stop chasing job titles. Start chasing knowledge. The title doesn't make you competent.
You don't have Netflix's problems. You have 3 developers and a Postgres database.
Reddit moved their comments system from Python to Go. The unglamorous reality of migration.
# What was needed:
def apply_discount(order, code):
if code == "SAVE10":
order.total *= 0.9
return order
# What was built:
class DiscountStrategyFactory:
def create_strategy(self, code: str) -> IDiscountStrategy:
return self._registry.get(code, NullDiscountStrategy())
class PercentageDiscountStrategy(IDiscountStrategy):
def __init__(self, percentage: float):
self._percentage = percentage
def apply(self, order: Order) -> Order:
order.total *= (1 - self._percentage)
return order
# + 3 more files, 2 interfaces, 1 registry# Version 1: if-statement
def get_discount(code):
if code == "SAVE10":
return 0.10
return 0
# Version 2: dictionary (when you have 5+ codes)
DISCOUNTS = {"SAVE10": 0.10, "VIP20": 0.20}
def get_discount(code):
return DISCOUNTS.get(code, 0)
# Version 3: database (when you need admin UI)
def get_discount(code):
return Discount.objects.filter(code=code).first()