# Code Smells: Symptom, Cause, Cure

Working code can still be hard to change, and it usually shows it: a code smell is a symptom you can see, like a cough, that points to a problem underneath; this lesson reads three smells in a food truck's ordering code as a doctor would, symptom, cause and cure, and shows why not every cure is a pattern.

Apprentice · OOP · Software Development · Updated November 17, 2026

By Gregor Dzierzon

## After this lesson you can

- Read a code smell as a doctor would: the symptom you see, the cause underneath, and the cure
- Spot three common smells: an if chain that grows, the same if in several places, and a class with many jobs
- Choose a small refactoring, not a pattern, when that's all a smell needs

## Key takeaways

- A code smell is a symptom: something you can see in working code that hints at a problem underneath, the way a cough hints at a cold.
- Read a smell in three steps: the symptom you see, the cause underneath it, and the cure.
- Three common smells: an if chain that grows with every new kind, the same if copied into several places, and one class doing many jobs.
- Not every cure is a pattern. The same if in three places is cured by pulling it into one method.

Taco Tuesday is a food truck with a small ordering app. It works: the menu board shows today's prices, the tablet at the window takes the order, and a receipt comes out. Then Rosa, who owns the truck, asks for a Friday special. The developer who opens the code spends an afternoon finding every place that knows about specials, and still misses one.

Nothing in the app was broken. But the code was telling them something before they started, the way a cough tells you something before you're sick in bed. By the end of this lesson you'll be able to hear it, and you'll have a name for what you heard: a **code smell**.

## The app, as it is today

Here is the food truck's code. One class, `FoodTruck`, works out each item's price, writes a line for the menu board, says how the customer paid, and writes the receipt. Today is Monday, and Monday's special is a burrito for $7 instead of $9:

```csharp
FoodTruck truck = new FoodTruck();
foreach (string item in new List<string> { "taco", "burrito", "quesadilla", "drink" })
{
    Console.WriteLine(truck.MenuLine(item, "Monday"));
}
Console.WriteLine(truck.Receipt(new List<string> { "burrito", "drink" }, "Monday", "card"));

// Taco Tuesday's ordering app: prices, the menu board, payments and receipts.
class FoodTruck
{
    public int Price(string item, string day)
    {
        if (item == "burrito" && day == "Monday")
        {
            return 7;
        }
        if (item == "taco") { return 4; }
        else if (item == "burrito") { return 9; }
        else if (item == "quesadilla") { return 7; }
        else if (item == "drink") { return 2; }
        return 0;
    }

    public string MenuLine(string item, string day)
    {
        string line = $"{item}: ${Price(item, day)}";
        if (item == "burrito" && day == "Monday")
        {
            line += " (special!)";
        }
        return line;
    }

    public string Payment(string method)
    {
        if (method == "card") { return "paid by card"; }
        else if (method == "cash") { return "paid in cash"; }
        return "not paid";
    }

    public string Receipt(List<string> items, string day, string method)
    {
        List<string> parts = new List<string>();
        int total = 0;
        foreach (string item in items)
        {
            string part = $"{item} ${Price(item, day)}";
            if (item == "burrito" && day == "Monday")
            {
                part += " (special!)";
            }
            parts.Add(part);
            total += Price(item, day);
        }
        return $"Receipt: {string.Join(", ", parts)} = ${total}, {Payment(method)}";
    }
}
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```java
// Taco Tuesday's ordering app: prices, the menu board, payments and receipts.
class FoodTruck {
    int price(String item, String day) {
        if (item.equals("burrito") && day.equals("Monday")) {
            return 7;
        }
        if (item.equals("taco")) { return 4; }
        else if (item.equals("burrito")) { return 9; }
        else if (item.equals("quesadilla")) { return 7; }
        else if (item.equals("drink")) { return 2; }
        return 0;
    }

    String menuLine(String item, String day) {
        String line = item + ": $" + price(item, day);
        if (item.equals("burrito") && day.equals("Monday")) {
            line += " (special!)";
        }
        return line;
    }

    String payment(String method) {
        if (method.equals("card")) { return "paid by card"; }
        else if (method.equals("cash")) { return "paid in cash"; }
        return "not paid";
    }

    String receipt(List<String> items, String day, String method) {
        List<String> parts = new ArrayList<>();
        int total = 0;
        for (String item : items) {
            String part = item + " $" + price(item, day);
            if (item.equals("burrito") && day.equals("Monday")) {
                part += " (special!)";
            }
            parts.add(part);
            total += price(item, day);
        }
        return "Receipt: " + String.join(", ", parts) + " = $" + total + ", " + payment(method);
    }
}

void main() {
    FoodTruck truck = new FoodTruck();
    for (String item : List.of("taco", "burrito", "quesadilla", "drink")) {
        IO.println(truck.menuLine(item, "Monday"));
    }
    IO.println(truck.receipt(List.of("burrito", "drink"), "Monday", "card"));
}
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```python
class FoodTruck:
    """Taco Tuesday's ordering app: prices, the menu board, payments and receipts."""

    def price(self, item, day):
        if item == "burrito" and day == "Monday":
            return 7
        if item == "taco":
            return 4
        elif item == "burrito":
            return 9
        elif item == "quesadilla":
            return 7
        elif item == "drink":
            return 2
        return 0

    def menu_line(self, item, day):
        line = f"{item}: ${self.price(item, day)}"
        if item == "burrito" and day == "Monday":
            line += " (special!)"
        return line

    def payment(self, method):
        if method == "card":
            return "paid by card"
        elif method == "cash":
            return "paid in cash"
        return "not paid"

    def receipt(self, items, day, method):
        parts = []
        total = 0
        for item in items:
            part = f"{item} ${self.price(item, day)}"
            if item == "burrito" and day == "Monday":
                part += " (special!)"
            parts.append(part)
            total += self.price(item, day)
        return f"Receipt: {', '.join(parts)} = ${total}, {self.payment(method)}"


truck = FoodTruck()
for item in ["taco", "burrito", "quesadilla", "drink"]:
    print(truck.menu_line(item, "Monday"))
print(truck.receipt(["burrito", "drink"], "Monday", "card"))
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```javascript
// Taco Tuesday's ordering app: prices, the menu board, payments and receipts.
class FoodTruck {
  price(item, day) {
    if (item === "burrito" && day === "Monday") {
      return 7;
    }
    if (item === "taco") { return 4; }
    else if (item === "burrito") { return 9; }
    else if (item === "quesadilla") { return 7; }
    else if (item === "drink") { return 2; }
    return 0;
  }

  menuLine(item, day) {
    let line = `${item}: $${this.price(item, day)}`;
    if (item === "burrito" && day === "Monday") {
      line += " (special!)";
    }
    return line;
  }

  payment(method) {
    if (method === "card") { return "paid by card"; }
    else if (method === "cash") { return "paid in cash"; }
    return "not paid";
  }

  receipt(items, day, method) {
    const parts = [];
    let total = 0;
    for (const item of items) {
      let part = `${item} $${this.price(item, day)}`;
      if (item === "burrito" && day === "Monday") {
        part += " (special!)";
      }
      parts.push(part);
      total += this.price(item, day);
    }
    return `Receipt: ${parts.join(", ")} = $${total}, ${this.payment(method)}`;
  }
}

const truck = new FoodTruck();
for (const item of ["taco", "burrito", "quesadilla", "drink"]) {
  console.log(truck.menuLine(item, "Monday"));
}
console.log(truck.receipt(["burrito", "drink"], "Monday", "card"));
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```typescript
// Taco Tuesday's ordering app: prices, the menu board, payments and receipts.
class FoodTruck {
  price(item: string, day: string): number {
    if (item === "burrito" && day === "Monday") {
      return 7;
    }
    if (item === "taco") { return 4; }
    else if (item === "burrito") { return 9; }
    else if (item === "quesadilla") { return 7; }
    else if (item === "drink") { return 2; }
    return 0;
  }

  menuLine(item: string, day: string): string {
    let line = `${item}: $${this.price(item, day)}`;
    if (item === "burrito" && day === "Monday") {
      line += " (special!)";
    }
    return line;
  }

  payment(method: string): string {
    if (method === "card") { return "paid by card"; }
    else if (method === "cash") { return "paid in cash"; }
    return "not paid";
  }

  receipt(items: string[], day: string, method: string): string {
    const parts: string[] = [];
    let total = 0;
    for (const item of items) {
      let part = `${item} $${this.price(item, day)}`;
      if (item === "burrito" && day === "Monday") {
        part += " (special!)";
      }
      parts.push(part);
      total += this.price(item, day);
    }
    return `Receipt: ${parts.join(", ")} = $${total}, ${this.payment(method)}`;
  }
}

const truck = new FoodTruck();
for (const item of ["taco", "burrito", "quesadilla", "drink"]) {
  console.log(truck.menuLine(item, "Monday"));
}
console.log(truck.receipt(["burrito", "drink"], "Monday", "card"));
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

Every price is right, and the receipt adds up. If a teacher graded this program on its output, it would pass. And yet Rosa's Friday special is going to hurt.

## Reading it like a doctor

A doctor doesn't stop at "you have a cough". They work in three steps: **the symptom** you can see (the cough), **the cause** underneath it (a cold, an allergy), and **the cure** for that cause (rest, not cough drops forever). Treating only the symptom makes it come back.

![A doctor's clipboard chart with three labeled rows, Symptom, Cause and Cure, each with a short handwritten line: Symptom "a cough", Cause "a cold", Cure "rest and fluids"](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/c25a25d99f154920a06b3f4fa1d807ed.webp)

Programmers read code the same way. A **code smell** is a symptom: something you can see in code that works, which hints at a problem underneath. The name comes from the programmer Kent Beck in the 1990s, and it fits: a smell isn't proof of anything, but it tells you where to look. Here are the three in the food truck's code.

**1. An `if` chain that grows.** *Symptom:* `Price` has an `if` for every item on the menu, and `Payment` has one for every way to pay. Each new item, and each new way to pay, is another `else if`. *Cause:* the list of kinds (items, payments) is written into the code that uses it, so the code changes every time the list does. *Cure:* give the list a home of its own, as data or as a class for each kind. The next lesson starts on this one, and later patterns finish it.

**2. The same `if` in three places.** *Symptom:* `item == "burrito" && day == "Monday"` appears in `Price`, in `MenuLine` and in `Receipt`. *Cause:* one decision ("is this today's special?") has no home, so each method makes it again. Friday's special needs all three edited, and missing one gives a menu board that disagrees with the receipt. Catalogs of smells call this **duplicated code**. *Cure:* give the decision one home (below).

**3. One class with four jobs.** *Symptom:* `FoodTruck` prices items, writes the menu board, handles payments and writes receipts. It changes when Rosa changes a price, when the board's layout changes, when a new card reader arrives, and when the receipt gets a tip line. *Cause:* four separate reasons to change are packed into one class, so every change risks the other three. Catalogs call this a **large class**. *Cure:* split it by reason to change, which is the first idea in the chapter *SOLID in Plain Words*.

![A table of the food truck's three smells with the columns Smell, Symptom, Cause and Cure: an if chain that grows, the same if in three places, and one class with four jobs, each with its symptom, its cause and its cure](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/224965951d974c8d87e01789fdcf16b0.webp)

| Smell | Symptom | Cause | Cure |
|---|---|---|---|
| An `if` chain that grows | an `else if` for every new item or payment | the list of kinds is written into the code that uses it | give the list its own home (*Find What Changes and Fence It Off*) |
| The same `if` in three places | one check copied into `Price`, `MenuLine` and `Receipt` | one decision has no home | pull it into one method |
| One class with four jobs | `FoodTruck` changes for four different reasons | four reasons to change in one class | split it by reason to change (*Single Responsibility*) |

## What would you try?

Take smell 2, the copied special check. Friday's special is coming. What would you do?

**Add the Friday check in all three places.** It works, if you find all three. The next special needs the same search, and the one after that. The cause is still there.

**Leave a comment above each copy:** "keep these three in step!". Comments don't run. The next person to edit one copy reads the comment, means to update the others, and gets called to the window.

**Reach for a design pattern.** Patterns are good answers to big problems, and this one is small. One decision copied three times doesn't need a new class, an interface and a diagram.

What the cause needs is simpler: the decision, made in **one** place, and asked for by everyone else.

## The cure: one place for one decision

Pull the check into a method of its own, `IsSpecial`, and have all three places ask it. Nothing else changes:

```csharp
FoodTruck truck = new FoodTruck();
foreach (string item in new List<string> { "taco", "burrito", "quesadilla", "drink" })
{
    Console.WriteLine(truck.MenuLine(item, "Monday"));
}
Console.WriteLine(truck.Receipt(new List<string> { "burrito", "drink" }, "Monday", "card"));

class FoodTruck
{
    // The one place that decides what today's special is.
    public bool IsSpecial(string item, string day) => item == "burrito" && day == "Monday";

    public int Price(string item, string day)
    {
        if (IsSpecial(item, day))
        {
            return 7;
        }
        if (item == "taco") { return 4; }
        else if (item == "burrito") { return 9; }
        else if (item == "quesadilla") { return 7; }
        else if (item == "drink") { return 2; }
        return 0;
    }

    public string MenuLine(string item, string day)
    {
        string line = $"{item}: ${Price(item, day)}";
        if (IsSpecial(item, day))
        {
            line += " (special!)";
        }
        return line;
    }

    public string Payment(string method)
    {
        if (method == "card") { return "paid by card"; }
        else if (method == "cash") { return "paid in cash"; }
        return "not paid";
    }

    public string Receipt(List<string> items, string day, string method)
    {
        List<string> parts = new List<string>();
        int total = 0;
        foreach (string item in items)
        {
            string part = $"{item} ${Price(item, day)}";
            if (IsSpecial(item, day))
            {
                part += " (special!)";
            }
            parts.Add(part);
            total += Price(item, day);
        }
        return $"Receipt: {string.Join(", ", parts)} = ${total}, {Payment(method)}";
    }
}
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```java
class FoodTruck {
    // The one place that decides what today's special is.
    boolean isSpecial(String item, String day) {
        return item.equals("burrito") && day.equals("Monday");
    }

    int price(String item, String day) {
        if (isSpecial(item, day)) {
            return 7;
        }
        if (item.equals("taco")) { return 4; }
        else if (item.equals("burrito")) { return 9; }
        else if (item.equals("quesadilla")) { return 7; }
        else if (item.equals("drink")) { return 2; }
        return 0;
    }

    String menuLine(String item, String day) {
        String line = item + ": $" + price(item, day);
        if (isSpecial(item, day)) {
            line += " (special!)";
        }
        return line;
    }

    String payment(String method) {
        if (method.equals("card")) { return "paid by card"; }
        else if (method.equals("cash")) { return "paid in cash"; }
        return "not paid";
    }

    String receipt(List<String> items, String day, String method) {
        List<String> parts = new ArrayList<>();
        int total = 0;
        for (String item : items) {
            String part = item + " $" + price(item, day);
            if (isSpecial(item, day)) {
                part += " (special!)";
            }
            parts.add(part);
            total += price(item, day);
        }
        return "Receipt: " + String.join(", ", parts) + " = $" + total + ", " + payment(method);
    }
}

void main() {
    FoodTruck truck = new FoodTruck();
    for (String item : List.of("taco", "burrito", "quesadilla", "drink")) {
        IO.println(truck.menuLine(item, "Monday"));
    }
    IO.println(truck.receipt(List.of("burrito", "drink"), "Monday", "card"));
}
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```python
class FoodTruck:
    def is_special(self, item, day):
        """The one place that decides what today's special is."""
        return item == "burrito" and day == "Monday"

    def price(self, item, day):
        if self.is_special(item, day):
            return 7
        if item == "taco":
            return 4
        elif item == "burrito":
            return 9
        elif item == "quesadilla":
            return 7
        elif item == "drink":
            return 2
        return 0

    def menu_line(self, item, day):
        line = f"{item}: ${self.price(item, day)}"
        if self.is_special(item, day):
            line += " (special!)"
        return line

    def payment(self, method):
        if method == "card":
            return "paid by card"
        elif method == "cash":
            return "paid in cash"
        return "not paid"

    def receipt(self, items, day, method):
        parts = []
        total = 0
        for item in items:
            part = f"{item} ${self.price(item, day)}"
            if self.is_special(item, day):
                part += " (special!)"
            parts.append(part)
            total += self.price(item, day)
        return f"Receipt: {', '.join(parts)} = ${total}, {self.payment(method)}"


truck = FoodTruck()
for item in ["taco", "burrito", "quesadilla", "drink"]:
    print(truck.menu_line(item, "Monday"))
print(truck.receipt(["burrito", "drink"], "Monday", "card"))
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```javascript
class FoodTruck {
  // The one place that decides what today's special is.
  isSpecial(item, day) {
    return item === "burrito" && day === "Monday";
  }

  price(item, day) {
    if (this.isSpecial(item, day)) {
      return 7;
    }
    if (item === "taco") { return 4; }
    else if (item === "burrito") { return 9; }
    else if (item === "quesadilla") { return 7; }
    else if (item === "drink") { return 2; }
    return 0;
  }

  menuLine(item, day) {
    let line = `${item}: $${this.price(item, day)}`;
    if (this.isSpecial(item, day)) {
      line += " (special!)";
    }
    return line;
  }

  payment(method) {
    if (method === "card") { return "paid by card"; }
    else if (method === "cash") { return "paid in cash"; }
    return "not paid";
  }

  receipt(items, day, method) {
    const parts = [];
    let total = 0;
    for (const item of items) {
      let part = `${item} $${this.price(item, day)}`;
      if (this.isSpecial(item, day)) {
        part += " (special!)";
      }
      parts.push(part);
      total += this.price(item, day);
    }
    return `Receipt: ${parts.join(", ")} = $${total}, ${this.payment(method)}`;
  }
}

const truck = new FoodTruck();
for (const item of ["taco", "burrito", "quesadilla", "drink"]) {
  console.log(truck.menuLine(item, "Monday"));
}
console.log(truck.receipt(["burrito", "drink"], "Monday", "card"));
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

```typescript
class FoodTruck {
  // The one place that decides what today's special is.
  isSpecial(item: string, day: string): boolean {
    return item === "burrito" && day === "Monday";
  }

  price(item: string, day: string): number {
    if (this.isSpecial(item, day)) {
      return 7;
    }
    if (item === "taco") { return 4; }
    else if (item === "burrito") { return 9; }
    else if (item === "quesadilla") { return 7; }
    else if (item === "drink") { return 2; }
    return 0;
  }

  menuLine(item: string, day: string): string {
    let line = `${item}: $${this.price(item, day)}`;
    if (this.isSpecial(item, day)) {
      line += " (special!)";
    }
    return line;
  }

  payment(method: string): string {
    if (method === "card") { return "paid by card"; }
    else if (method === "cash") { return "paid in cash"; }
    return "not paid";
  }

  receipt(items: string[], day: string, method: string): string {
    const parts: string[] = [];
    let total = 0;
    for (const item of items) {
      let part = `${item} $${this.price(item, day)}`;
      if (this.isSpecial(item, day)) {
        part += " (special!)";
      }
      parts.push(part);
      total += this.price(item, day);
    }
    return `Receipt: ${parts.join(", ")} = $${total}, ${this.payment(method)}`;
  }
}

const truck = new FoodTruck();
for (const item of ["taco", "burrito", "quesadilla", "drink"]) {
  console.log(truck.menuLine(item, "Monday"));
}
console.log(truck.receipt(["burrito", "drink"], "Monday", "card"));
```

```text
taco: $4
burrito: $7 (special!)
quesadilla: $7
drink: $2
Receipt: burrito $7 (special!), drink $2 = $9, paid by card
```

Same output, line for line. The program does exactly what it did; only its shape changed. A change like this, which improves the code's shape without changing what it does, is called a **refactoring**, and *pull out a method* is the most common one there is. Now "is this the special?" is answered in one place, and the menu board and the receipt can't disagree.

**Try it.** Rosa wants the special on Fridays too. Change only `IsSpecial` so it also says yes to a burrito on a Friday, and print Friday's menu. The board and the receipt both pick it up.

## Not every cure is a pattern

That cure had no pattern in it, and that's the lesson's most useful idea. A smell tells you there's a cause; it doesn't tell you the cause is big. Most smells are cured by a small refactoring: pull out a method, rename something, move a method to the class whose data it uses. A pattern is the cure when the cause keeps growing back: when a new kind arrives every month, or many people need to plug in their own piece.

The other two smells are bigger, and this module comes back to both: the growing `if` chain in the very next lesson, and the class with four jobs in *SOLID in Plain Words*. Every pattern lesson in this course starts the same way: a smell you can see, the cause underneath it, and then the cure.

## In your textbook

The idea and the name were made popular by Kent Beck and Martin Fowler in Fowler's 1999 book *Refactoring*, which lists more than twenty smells with names like *duplicated code*, *large class*, *long method* and *switch statements*. A class or a textbook may give you that list to learn. The names are useful vocabulary, but the skill is the three steps: see the symptom, find the cause, choose the smallest cure that fixes it.

## Check yourself

2 questions to try on the lesson page.

## So what

Code can work and still be hard to change, and it usually shows you where before it hurts. Read the symptom, find the cause, and pick the smallest cure that fixes the cause, which is often one method.

## Key terms

- [Code Smell](https://www.ask-codey.com/glossary/code-smell)
- [Duplicated Code](https://www.ask-codey.com/glossary/duplicated-code)
- [Large Class](https://www.ask-codey.com/glossary/large-class)
- [Repeated Switch](https://www.ask-codey.com/glossary/repeated-switch)
- [Extract Method](https://www.ask-codey.com/glossary/extract-method)
- [Refactoring](https://www.ask-codey.com/glossary/refactoring)

## Cheat sheets

- [Code Smells: Symptom, Cause, Cure](https://www.ask-codey.com/cheat-sheets/dp-code-smells-cheat-sheet)

Source: https://www.ask-codey.com/lessons/dp-code-smells
