Much of the classic advice around "Clean Code"—such as never letting a function exceed 10 lines or creating an interface for every single class—often does more harm than good in modern enterprise production. Senior engineers recognize that maintainability is about cognitive load, predictability, and ease of modification.
1. Locality of Behavior over Dogmatic DRY
The Don't Repeat Yourself (DRY) principle is one of the first heuristics junior engineers learn. However, dogmatic DRY frequently leads to the worst kind of technical debt: premature abstraction. When two superficially similar routines are forced into a single generic helper, the helper quickly accumulates boolean flags, conditional branches, and edge-case exceptions.
Senior engineers prefer Locality of Behavior (LoB): keeping related logic close together so that another engineer can read a file from top to bottom without jumping through seven levels of indirection. Duplication is far cheaper than the wrong abstraction.
2. Naming for Business Intent, Not Mechanical Implementation
Names in software should reveal intent and domain context rather than the underlying data structure:
- Avoid:
userListArray,handleData(),processInfo() - Prefer:
activeSubscribers,reconcileBillingDiscrepancies(),verifyEmailToken()
If a variable name requires a comment above it to explain what it represents, the variable is poorly named.
3. The Guard Clause & Return Early Pattern
Deeply nested if-else structures create unnecessary mental indentation and force developers to track multiple branches simultaneously. Inverting conditionals into early returns keeps the "happy path" flat and readable:
// Clean: Guard clauses exit immediately upon invalid conditions
async function authenticateRequest(req: Request): Promise<SessionUser> {
const token = req.headers.get('authorization')?.replace('Bearer ', '');
if (!token) {
throw new UnauthorizedError('Missing bearer token');
}
const payload = await verifyJwtSignature(token);
if (!payload || payload.isExpired) {
throw new UnauthorizedError('Token is expired or invalid');
}
const user = await userRepo.findById(payload.sub);
if (!user || user.isSuspended) {
throw new ForbiddenError('Account is suspended or deactivated');
}
// The happy path remains un-nested and easy to follow
return user;
}
4. Parse, Don't Validate
Traditional validation checks data and returns a boolean. If valid, the code passes the unvalidated object downstream, meaning subsequent functions have no guarantee that the data remains pristine.
Modern clean code uses schema parsers (such as Zod in TypeScript, Pydantic in Python, or Serde in Rust) to parse raw input into strongly typed domain objects at the system boundary. Once parsed, the rest of the application can safely rely on the compiler without defensive re-checking.
- Code is read ten times more often than it is written. Optimize for readability over briefness.
- Write code that is easy to delete, not code that is impossible to replace.
- Tests are the ultimate documentation. A clean test suite explains the business domain better than a wiki.