Creative Engineer Spin

Code Smells: 20 Examples and How to Fix Them

The surface signs that a codebase is getting harder to change, named the way engineers name them: what each smell looks like, how it shows up before anyone reads the code, and what refactoring it involves.

From the editors of Creative Engineer Spin · Updated

A code smell is a pattern in source code that hints at a deeper design problem. The term comes from Kent Beck and was popularised by Martin Fowler's book Refactoring. A smell is not a bug: the code still works. It is a sign that the next change will be slower, riskier or more surprising than it should be.

Smells are useful because they have names. When an engineer says a module has shotgun surgery or feature envy, they are pointing to a known shape with a known way out. Static analysis tools such as SonarQube and most linters flag some of them automatically; the rest are found by reading the code and noticing where changes keep hurting.

The examples below are the smells that turn up most often in MVPs, freelancer handoffs and apps written with AI coding tools. They are grouped the way they are usually taught, with a last group for the ones AI-generated code adds. Each says what the smell looks like, how it tends to show up for a founder or product team, and what fixing it involves.

A smell is a prompt to look closer, not an order to rewrite. Every real codebase has some. The ones worth fixing first are those in the code you are about to change.

Bloaters

Code that has grown too big to hold in your head at once. Nobody writes it that way on purpose; it accumulates one quick addition at a time.

  1. 01Long method

    What it looks like
    A single function hundreds of lines long that validates input, queries the database, applies business rules and formats the response, with comments marking each section.
    How you notice it
    Small changes to one step break another, and estimates for "just tweaking the checkout" keep coming back larger than expected.
    What fixing it involves
    Extract each section into a well-named function of its own, starting where the comments already mark the seams, with a test around the whole before you begin.
  2. 02Large class (the god object)

    What it looks like
    One class, service or component that knows about users, billing, notifications and reporting, with dozens of methods and fields.
    How you notice it
    Every feature touches the same file, developers step on each other's changes, and onboarding someone new starts with "don't touch that file unless you have to."
    What fixing it involves
    Group its methods by the data they use, move each group into its own class or module behind the same interface, and shrink the original one responsibility at a time.
  3. 03Long parameter list

    What it looks like
    Functions that take six, eight or ten arguments, several of them booleans like true, false, true whose meaning you can only learn by opening the definition.
    How you notice it
    Calls get the arguments in the wrong order and the bug only shows for some users, in some cases.
    What fixing it involves
    Pass an object with named fields, or split the function so each version takes only what it needs. A boolean that switches behaviour usually means two functions.
  4. 04Primitive obsession

    What it looks like
    Money stored as plain floating-point numbers, statuses as free-text strings, and email addresses, phone numbers and IDs passed around as unchecked strings.
    How you notice it
    Totals are off by a cent, a typo like "canceled" versus "cancelled" leaves records in a state no screen handles, and the same validation is written over and over.
    What fixing it involves
    Introduce small types for the concepts that matter (a Money type in whole cents, an enum of statuses, a validated Email) and route new code through them.
  5. 05Data clumps

    What it looks like
    The same group of values (street, city, postcode, country; or start date, end date, time zone) passed together through function after function.
    How you notice it
    Adding one field, such as a second address line, means editing dozens of signatures and missing a few.
    What fixing it involves
    Give the group a name and a type of its own, then replace the loose values with it wherever they travel together.

Conditional and structure smells

Code that uses branching and inheritance in ways that fight the design instead of expressing it. These are often called object-orientation abusers, though they appear in any style of code.

  1. 06Repeated switch statements

    What it looks like
    The same switch or if/else chain on a plan, user type or product kind, copied into pricing, permissions, emails and the UI.
    How you notice it
    Adding a new plan or customer type is a big project, and the first release always misses one of the places it should have changed.
    What fixing it involves
    Put the behaviour that varies in one place per type, with a lookup table, a strategy object or polymorphism, so a new type means one new entry instead of a hunt.
  2. 07Refused bequest

    What it looks like
    A subclass or component that inherits methods it doesn't want and overrides them to do nothing or to throw an error.
    How you notice it
    Shared code changes in the parent and something unrelated breaks in a child nobody thought used it.
    What fixing it involves
    Stop inheriting where the child isn't really a kind of the parent; share the useful parts by composition instead.
  3. 08Temporary field

    What it looks like
    Fields on an object that are only set during one process and are empty or stale the rest of the time.
    How you notice it
    Errors about missing values that only happen when a feature is used in an unusual order, which makes them hard to reproduce.
    What fixing it involves
    Move the fields and the process that uses them into a separate object that exists only while the process runs.

Change preventers

Smells that make one change spread across the codebase. They are the ones a founder feels most directly, as features that take far longer than they look.

  1. 09Shotgun surgery

    What it looks like
    One small change in behaviour (a new field on the sign-up form, a renamed status) means edits in ten files across the frontend, the API and background jobs.
    How you notice it
    Simple requests turn into multi-day tickets, and something is almost always forgotten, so the change ships with a follow-up bug.
    What fixing it involves
    Move the scattered pieces of each concept together into one module, so the next change of that kind happens in one place.
  2. 10Divergent change

    What it looks like
    One module that has to be edited for unrelated reasons: when the database changes, when the email copy changes and when the pricing changes.
    How you notice it
    Two people working on unrelated features keep conflicting in the same file, and reviews are hard because every change mixes concerns.
    What fixing it involves
    Split the module along the reasons it changes, so each new piece has one job and one kind of change that touches it.

Dispensables

Code the product would be better without. Removing it is often the cheapest improvement available, and the one teams put off longest.

  1. 11Duplicated code

    What it looks like
    The same logic copied into several places, each copy drifting slightly as it gets patched on its own.
    How you notice it
    A bug fixed in one place comes back from another, and the product behaves differently depending on which screen a user came from.
    What fixing it involves
    Extract the logic into one shared function, pin its behaviour with tests, and move the copies onto it one at a time.
  2. 12Dead code

    What it looks like
    Functions nothing calls, feature flags that have been on for a year, commented-out blocks, and whole screens no menu links to.
    How you notice it
    Developers spend time reading, updating and debugging code that never runs, and nobody is sure what is safe to delete.
    What fixing it involves
    Confirm it is unused with search and usage logs, delete it, and trust version control to keep the history.
  3. 13Speculative generality

    What it looks like
    Abstractions, plugin systems and configuration options built for needs that never arrived, with one implementation each.
    How you notice it
    Simple features need changes in several layers of indirection, and new developers ask why something so small is so complicated.
    What fixing it involves
    Collapse abstractions that have a single user back into plain code. Add the flexibility again when a second real case shows up.
  4. 14Comments that explain confusing code

    What it looks like
    Long comments describing what a block does step by step, or warnings like "don't change this, it breaks billing."
    How you notice it
    The comments go out of date, and people follow them instead of the code, which is the version that actually runs.
    What fixing it involves
    Rename and extract until the code says what the comment said, then keep comments for why a decision was made rather than what the code does.

Couplers

Smells about how pieces of the code depend on each other. Too much coupling means no part can change, be tested or be replaced on its own.

  1. 15Feature envy

    What it looks like
    A function that spends most of its time reaching into another object's data, such as an invoice screen that calculates tax, discounts and totals from the order's fields itself.
    How you notice it
    The same calculation exists in several screens and gives slightly different answers in each.
    What fixing it involves
    Move the function next to the data it uses, so the order calculates its own totals and every screen asks it.
  2. 16Inappropriate intimacy

    What it looks like
    Two modules that read and write each other's internal fields, or call each other's private helpers, instead of going through a defined interface.
    How you notice it
    Neither part can be changed, tested or replaced alone, so a plan to swap a payment provider or split out a service stalls.
    What fixing it involves
    Define what each module offers the other, route calls through that interface, and hide everything else.

    Read more: Monolithic Architecture Trade-offs for Early-Stage SaaS Products

  3. 17Message chains

    What it looks like
    Long chains like order.customer.account.plan.limits.seats that walk through several objects to reach one value.
    How you notice it
    A change to how accounts or plans are stored breaks code all over the app, including places that have nothing to do with accounts.
    What fixing it involves
    Ask the nearest object for what you need (order.seatLimit()) and let it handle the walk, so the route lives in one place.
  4. 18Middle man

    What it looks like
    A class or service whose methods do nothing but pass the call on to another one.
    How you notice it
    Following any feature through the code means opening several files that each add nothing, which slows every investigation.
    What fixing it involves
    Remove the layer and call the real object directly, unless the layer exists to protect you from a vendor or a part you plan to replace.

Smells common in AI-generated code

Apps built quickly with AI coding tools show every smell above, and two more that come from generating code one prompt at a time without a shared plan.

  1. 19Errors caught and silently ignored

    What it looks like
    Try/catch blocks that catch everything and do nothing, log to the console, or return an empty value, added to make an error message go away.
    How you notice it
    Data quietly goes missing, payments or emails fail without anyone being told, and bug reports arrive with no error in any log.
    What fixing it involves
    Let unexpected errors surface to error tracking, handle only the specific failures you can recover from, and show the user a clear message when something fails.

    Read more: Technical Debt Created by AI-Generated Code in Production

  2. 20Several ways of doing the same thing

    What it looks like
    Three HTTP clients, two date libraries, a mix of state-management approaches and different folder layouts, because each prompt solved its problem in whatever way the tool chose that day.
    How you notice it
    Every developer, and every AI session, has to work out which pattern to follow, so the inconsistency grows with each change.
    What fixing it involves
    Pick one way for each concern, write it down where people and AI tools will read it, and migrate the others as the code around them is changed.

    Read more: Code Review Standards for AI-Assisted Pull Requests

What to do when your codebase smells

  1. 1

    Ask where changes hurt

    Ask the people working on the product which areas are slow or scary to change. Smells in those areas cost money every week; smells in code nobody touches cost almost nothing.

  2. 2

    Put tests around the area first

    Refactoring means changing structure without changing behaviour, and only tests prove the behaviour didn't change. Where there are none, start with a few that pin down what the code does today.

  3. 3

    Refactor in small steps alongside feature work

    Clean up the code a feature is about to touch as part of building it, one small, reviewable change at a time, rather than scheduling a separate cleanup project that keeps slipping.

  4. 4

    Let tools catch the repeat offenders

    Turn on a linter and a static analysis tool in the pull request checks so new duplication, dead code and overly long functions are flagged before they merge.

  5. 5

    Know when it's more than a smell

    If the same smells keep pointing at the data model or the way the system is split, the problem is architectural. That is when a wider review, and the refactor-or-rebuild question, are worth raising.

Further reading

More in Startup Technical Debt →