Skip to main content

Command Palette

Search for a command to run...

Why Clean Code Matters More Than Ever

Published
4 min read
Why Clean Code Matters More Than Ever

Introduction

Clean code always mattered. But now it matters more. AI reads your code. AI writes your code. The cleaner your codebase is. The better AI understands it. The better AI writes new code that fits in. Garbage in. Garbage out. A messy codebase steers AI in the wrong direction. A clean one steers it right.

Type Safety Steers AI

Types are not just for you. They are for AI. Strong type safety gives AI guardrails. It knows what a function expects. It knows what it returns. It catches mistakes before they happen. When AI generates code in a typed codebase. It follows the types. It respects the contracts. Without types. AI guesses. And guessing means bugs.

Lint Rules I Like

Lint rules keep your code clean and consistent. Consistency is what matters here. When your codebase follows strict rules. AI picks up on the patterns and writes code that follows them too.

Max lines per file. I cap files at 800 lines. Skipping blanks and comments. This forces you to break things apart. Small files. Clear responsibilities. AI works better with small focused files too. It has less noise to deal with.

No await in loop. This one catches a common performance trap. Awaiting inside a loop means sequential requests when you probably want parallel ones. AI loves doing this. The lint rule stops it.

No nested ternary. This one is big. AI loves deeply nested ternaries. Three or four levels deep. Unreadable. This rule kills that habit immediately. One level. That is it. Readable. Simple.

Array type consistency. I enforce Array<string> over string[]. Pick one style. Stick to it. Consistency helps AI follow the same pattern everywhere.

Boolean naming convention. Booleans must start with is. should. has. are. can. was. This makes code read like English. isActive. hasPermission. canEdit. You know what it is just by reading the name. AI follows this convention too when it sees your codebase doing it.

Prettier For Consistency

I use Prettier with strict settings. Single quotes. No semicolons. Two space tabs. Print width at 80. Trailing commas. Tailwind CSS plugin for class sorting. The specific choices do not matter as much. What matters is that everything looks the same. Every file. Every line. When AI writes new code in a consistent codebase. It matches the style. No reformatting needed. No messy diffs. Just clean code that fits in.

Clean Code Is Table Stakes. Think About API Boundaries.

Here is what actually matters more than clean code. Thinking about your API boundaries. How your modules talk to each other. What the contracts look like. Where the separation of concerns lives. Clean code is the baseline. The real work is designing the right abstractions. The right interfaces. The right boundaries between systems. This is where you think. Not AI.

Good boundaries also make AI way more effective. When things are scoped and colocated. AI can work in one place without breaking another. It can move things around safely. It can refactor a module without touching the rest of your system. Tight boundaries mean AI operates in a small focused area with clear inputs and outputs. Loose boundaries mean AI pulls on one thread and unravels everything. The better your architecture. The better AI works inside it.

Always Use Objects As Function Parameters

This is a small thing that makes a big difference. Instead of passing three separate arguments to a function. Pass one object.

Bad. createUser(name, email, role). You and AI have to remember the order. You have to look up what each position means.

Good. createUser({ name, email, role }). Every argument is labeled. You see exactly what the function expects. AI sees it too. No guessing. No wrong order. Easy to add new parameters later without breaking anything.

This pattern is simple. It makes your code more readable. It makes AI more accurate when calling your functions. Small wins like this compound.

Why Clean Code Matters More Than Ever