Code smells that make a codebase hard to understand
The patterns that cost readers the most time: misleading names, hidden side effects, deep indirection, boolean flags, magic values and scattered logic, with fixes.
Some code is hard to understand because the problem is hard. A lot of it is hard to understand for avoidable reasons. These are the patterns that cost readers the most time, and simple ways to fix each one.
Names that lie
A function called getUser that also updates a "last seen" timestamp. A variable called total that excludes tax. Misleading names are worse than vague ones, because readers trust them and stop reading.
Fix: rename to describe everything the function does (getUserAndTouchLastSeen), or split the side effect out.
Hidden side effects
Functions that look like queries but change state, send messages or write to the cache. Readers skip them while tracing, then wonder why behaviour changes.
Fix: separate commands (which change things) from queries (which return things). Make side effects visible at the call site.
Indirection without purpose
A call that passes through a controller, a service, a manager, a helper and an adapter before doing anything. Each layer adds a file to open and a name to remember.
Fix: remove layers that only pass arguments through. Keep layers that carry real responsibility.
Boolean parameters
createUser(data, true, false): nobody knows what true and false mean without opening the definition.
Fix: use an options object (createUser(data, { sendWelcomeEmail: true })) or separate functions.
Magic values
if (status === 3) or setTimeout(retry, 86400000). Readers have to guess what the number means.
Fix: named constants (OrderStatus.Shipped, ONE_DAY_MS) and enums.
Scattered logic for one concept
The rules for whether an order can be refunded, split across the UI, two API routes and a background job, each slightly different.
Fix: one function that owns the rule, called from everywhere it applies.
Distance between related code
Event handlers registered far from the code that emits the events; configuration that changes behaviour defined in a different package. Readers can't find the connection.
Fix: keep related code close, or leave a pointer comment ("handled in subscribers/orders.ts").
Comments that explain what, not why
// increment i adds nothing. A missing comment on total = Math.max(total, 0.5) costs the next reader an hour of history-digging.
Fix: comment the reasons, constraints and surprises; let code show the mechanics.
Dead code and stale flags
Branches that never run and flags that are always on double the paths a reader must consider. See finding dead code and understanding feature flags.
Measure the cost
A good test of understandability: how long does it take someone new to explain what happens on one important path? Tools that explain code, like RepoGrasp, also struggle with these smells: a misleading name can mislead a model too. Cleaning them up helps people and tools alike.