Skip to content
Getting StartedChapter 2 / 57Beginner6 min read

Core Philosophy

Clean code principles YAGNI and KISS, maintainability over speed, explicit over implicit and a small design surface. The thinking behind all the rules.

On this page

1. What is this practice?

All the rules in this course come from six ideas:

IdeaMeaning
Maintainability over speedSaving 10 minutes today is a loss if it costs 2 hours tomorrow
Simplicity first (KISS, YAGNI)The simplest solution that works. Do not build what you do not need yet
Small design surfaceA new table, API field, flag or abstraction only when the need is proven
Explicit over implicitThe intent is clear from names and structure, not hidden magic
Delete over commentDo not comment out old code, delete it. Git has the history
Self-documentingThe code explains itself through its names and shape

KISS means "Keep It Simple, Stupid". YAGNI means "You Aren't Gonna Need It": do not write code today for an imaginary future need.

2. Why does it matter?

The real cost of software is not in writing it, it is in changing it. A feature is written once and then read, debugged and modified for years.

Speed and cleverness firstSimplicity and clarity first
Built a generic system for the future that was never usedOnly today's work, and build more if the need comes later
A config flag for everythingOne direct path, a flag only for a real runtime difference
A clever one-liner that only its author understandsSimple code that a new developer understands too
Old code commented out and left behindDeleted, and safe in Git history
Hours spent finding a bugThe flow is direct, so the bug shows up quickly

Every extra abstraction, flag or table is a promise you will have to keep forever. The fewer promises, the lighter the load.

3. When to follow it

LevelHow importantWhy
Learning projectVery important, especially YAGNIBeginners often build a "scalable architecture" and never finish the project
Production codeIn every PREvery new abstraction or table is a future burden for the team
Senior levelResponsibility for the decisionA senior decides when growing the design surface is really needed

4. Bad vs good code

Task: show the user's display name. Today there is only a first and last name.

ts
type NameFormat = "full" | "first" | "last" | "initials" | "reversed";

class NameFormatterFactory {
  static create(format: NameFormat, options: { uppercase?: boolean; separator?: string } = {}) {
    return new NameFormatter(format, options);
  }
}

const label = NameFormatterFactory.create("full", { separator: " " }).format(user);
ts
function displayName(user: User) {
  return `${user.firstName} ${user.lastName}`;
}

const label = displayName(user);
What is the difference?BadGood
NeedFive formats nobody asked forOnly what is needed today
Design surfaceFactory, class, options object, union typeOne function
Reading timeThree things to understandOne glance
Changing itTests and maintenance for every formatGrow it when the need comes

YAGNI does not mean never think about the future. It means write code that is easy to change later, not write every future case today.

Explicit over implicit

ts
export default function (d: any) {
  return fetch("/api/x", { method: "POST", body: JSON.stringify(d) });
}
ts
export function createInvoice(input: CreateInvoiceInput) {
  return api.post("/api/invoices", input);
}

In the second version the name, type and endpoint are all clear. There is nothing to guess.

5. How to apply it

Before building a new feature
Write today's real need in one line
Check whether existing code already does it
Think of the simplest solution that works
A new table, field, flag or abstraction? Prove it is needed
Make the intent clear with names and types
Delete code that is no longer useful

Ask one easy question about every design: "If I do not build this, what breaks today?" If the answer is "nothing", do not build it.

6. Exceptions and common mistakes

Some decisions are very expensive to change later: the database schema, a public API contract, the auth design. Thinking a little ahead here is not against YAGNI, it is responsibility. Even so, build only what is needed, and just keep it easy to change.

Mistake: Confusing simple with lazy

Why? Writing simple code is often harder. The first version is complex, and making it simple is the real work.

Better: Write a first draft, think about what you can remove, and then remove it.

Mistake: Making everything configurable

Why? Every flag doubles the code paths and increases the test cases.

Better: Use a flag only when the behavior really changes at runtime, otherwise keep one direct path.

Mistake: Keeping old code commented out

Why? The reader wonders whether it matters, and that code slowly becomes wrong.

Better: Delete it. If you need it back, you will find it in Git history.

Mistake: Taking shortcuts in the name of speed

Why? The minutes saved today turn into hours of debugging and rework next month.

Better: Write it clean from the start. It feels a little slower the first time, and then it gets fast.

7. What to learn before and after

Suggested order
Introduction
Core Philosophy
When to Learn What
Self-Documenting Code

Final quick revision

CheckQuestion
MaintainabilityWill someone else be able to change this easily 6 months from now?
KISSIs there a simpler solution?
YAGNIDo we really need this today?
Design surfaceIs a new table, field, flag or abstraction necessary?
ExplicitIs the intent clear from the name and type?
DeleteIs any dead code left?