Skip to content

Technical Debt: The Dirty Kitchen ๐Ÿฝ๏ธ๐Ÿงน โ€‹

In Agile, we often talk about Technical Debt. It sounds fancy, but it is a simple concept.

The Analogy: Cooking Dinner ๐Ÿณ โ€‹

Imagine you are cooking dinner (writing code).

  • Option A: You wash the dishes as you go. It takes a bit longer, but the kitchen stays clean.
  • Option B: You throw everything in the sink to cook faster. You eat sooner, but now you have a huge pile of dirty dishes.

Technical Debt is that pile of dirty dishes.

  • Clean Code: Washing dishes as you go.
  • Technical Debt: "I'll fix this messy code later."

Why is it called "Debt"? ๐Ÿ’ณ โ€‹

Like a credit card, a little bit of debt is okay!

  • Sometimes you need to cook fast because guests are arriving (Deadline).
  • So you leave the dishes (Bad Code) in the sink.

The Catch: You have to pay "Interest".

  • If you don't wash the dishes tomorrow, the food hardens. It becomes harder to clean.
  • If you don't refactor your bad code, adding new features becomes slower and harder.

Examples of Tech Debt in Python ๐Ÿ โ€‹

1. The "Magic Number" Debt โ€‹

Bad Code:

python
if score > 75:  # What is 75?
    print("Pass")

Refactored (Paid Debt):

python
PASSING_SCORE = 75
if score > PASSING_SCORE:
    print("Pass")

2. The "Copy-Paste" Debt โ€‹

You copied the same 10 lines of code into 5 different files.

  • Interest: If you find a bug in one, you have to fix it in 5 places.
  • Payment: Refactor it into a single function calculate_stuff() and import it.

3. The "No Tests" Debt โ€‹

You wrote a script but didn't write a test for it.

  • Interest: Every time you change the script, you are scared you broke it. You have to manually run it 10 times to check.
  • Payment: Write a pytest case so you can check it instantly.

How Agile Teams Handle Debt ๐Ÿ—๏ธ โ€‹

Agile teams don't ignore debt. We manage it.

  1. The Rule of Boy Scouting: "Leave the campground cleaner than you found it."
    • If you touch a messy file, fix one small thing (rename a variable, add a comment).
  2. Refactoring Tasks: We create specific tasks in our Backlog called "Refactor Login Module" (paying off debt).
  3. The "Definition of Done": We agree that a task isn't "Done" until the dishes are washed (code is linted and tested).

Task: Spot the Debt ๐Ÿง โ€‹

Task

Scenario: Your friend wrote this code to check if a user is an adult.

python
# check age
if int(input("Age? ")) >= 18:
    print("Adult")
else:
    print("Minor")

What is the debt here?

Possible Answer
  1. Hardcoded Logic: The input and logic are mixed. Hard to test automatically.
  2. Magic Number: 18 should be a constant like LEGAL_ADULT_AGE.
  3. No Error Handling: What if the user types "twenty"? It crashes.

Conclusion ๐ŸŽ“ โ€‹

It is okay to take on Debt (write quick-and-dirty code) to meet a deadline. But remember: You have to pay it back eventually, or your project will go bankrupt (become unmaintainable)!