Sitemap

What I Learned From Reviewing 10k Lines of Python Code

5 min readMar 12, 2026

--

You’re asked to review a massive pull request — 10,000 lines touching every corner of a service. There’s pressure to approve fast, but you know that what slips through here will live for years.

What surprised me most wasn’t the syntax issues — it was how small, structural decisions shaped everything: clarity, testability, and future bugs.

Here are the concrete lessons, patterns, and habits that surfaced again and again while reading those 10k lines of real-world Python.

Press enter or click to view image in full size

The Reality of Reading 10k Lines of Real Python

Big code reviews are not line-by-line marathons — they’re navigation challenges.

When I opened that PR, the first step wasn’t reading the diff. It was mapping the terrain:

  • I scanned the folder layout to understand how logic was grouped (or not).
  • I found the entrypoints: scripts, API routes, CLI commands.
  • I identified risky zones — big functions, untested modules, external dependencies.

Surprisingly, the worst bugs were not where I expected. The legacy modules were stable; it was the “new clean code” that broke invariants silently.

Big code reviews are about mapping the terrain first, not line-by-line perfection.

The Code Smells That Show Up Again and Again

After a few thousand lines, patterns emerge. These are the usual suspects.

1. God functions

Too much logic stuffed into one place:

def process_order(order_id):
data = get_data(order_id)
result = complex_business_logic(data)
notify_user(result)
log_to_db(order_id, result)
return result

Fix: separate I/O, business logic, and side effects. Each should have its own function.

2. Silent failures

try:
do_thing()
except Exception:
pass

No logs, no signal, no retry. Nothing good ever came from this. Fix it by at least logging or re-raising.

3. Implicit dependencies

Functions that magically use globals, configs, or environment variables. When you test them, they explode.

Make dependencies explicit via arguments or constructor injection.

4. Copy-paste variants

Tiny differences across nearly identical blocks — a refactor waiting to happen.

If a smell shows up dozens of times, it’s not a one-off mistake — it’s a design problem.

Design Patterns Seniors Use Without Naming Them

In the best-written modules, I noticed the same calm rhythm.

  • Clear separation of layers: domain logic stayed isolated from APIs, databases, or frameworks.
  • Explicit inputs and outputs: functions didn’t rely on hidden state.
  • Small abstractions: simple service or repository classes wrapped complex dependencies.

Example:

class PaymentService:
def __init__(self, gateway):
self.gateway = gateway

def charge(self, amount, user_id):
transaction = self.gateway.create_transaction(amount, user_id)
return transaction.status

No fancy jargon, no abstract base class. Just structure and intention.

Good design reads like obvious code, even if there’s a pattern behind it.

How Good Developers Write Debuggable and Testable Code

Some code felt like a breeze to understand and test. Here’s why.

Debuggable code

  • Logged actions and outcomes with context (user id, request id, key params).
  • Had clear, informative exceptions — not vague messages.
  • Avoided deep nesting and hidden mutations.

Example: before vs after

Before:

def calculate(a, b, c):
if a:
if b:
return a * b + c
return None

After:

def calculate(a, b, c):
if not a or not b:
raise ValueError("Missing required params")
return a * b + c

One line shorter, infinitely easier to debug.

Code that is easy to debug usually looks boring and explicit instead of clever.

Review Habits That Catch Bugs Before They Ship

When scanning large diffs, I stopped looking for style and started looking for behavior.

My mental checklist

  • What happens if an external call fails or times out?
  • Are there retries or fallbacks?
  • Does this function validate input and output?
  • Are invariants clearly enforced?

Instead of nitpicking formatting, I ask “what happens if…” — and that’s where the real issues hide.

The best review comments change how a teammate thinks, not just where they put a comma.

Refactor Tactics That Actually Survived the Next Release

Ideal refactors are nice in theory. In practice, only small, surgical changes survive deadlines.

What worked

  • Extracting one helper function that simplified five call sites.
  • Adding a tiny interface around a volatile dependency (e.g., external API).
  • Writing regression tests before touching risky logic.

What didn’t work

  • Reorganizing entire directories without tests.
  • Overabstracting for “future extensibility” that never came.

Incrementalism wins: fix the one pain point your teammates will actually keep.

Get Code With Ahmad’s stories in your inbox

Join Medium for free to get updates from this writer.

The best refactors are the ones that stick and make future changes cheaper.

How to Turn Code Reviews Into a Growth Engine

After reviewing enough code, you realize the process itself can level up a team.

How to make reviews scale knowledge

  • Collect recurring smells or patterns into short docs or checklists.
  • Encourage reviewers to ask why questions instead of dictating fixes.
  • Use review comments as prompts for brown bag sessions.

Personal habits that help

  • Keep a private log of “things I learned reviewing today.”
  • Revisit old PRs months later to see which choices aged well.

Treat every code review as a chance to train your eye and your judgment, not just to approve or reject.

Quick Reference: Junior vs Senior Style

  • Repeated code
    Junior fix — extract a util function
    Senior fix — extract a small, well-tested service or helper
  • Silent failure
    Junior fix — wrap in a broad try or except
    Senior fix — add logging, raise specific exceptions, and include context
  • Messy business logic
    Junior fix — add comments
    Senior fix — split by responsibility and back it with tests
  • Global config
    Junior fix — access it directly
    Senior fix — inject the dependency explicitly

Glossary

  • Code smell
    A recurring pattern that hints at deeper design problems
  • Refactor
    Changing the structure of code without altering its external behavior
  • Invariant
    A condition that must always remain true throughout execution
  • Regression
    A bug that reappears after it was previously fixed
  • Technical debt
    Tradeoffs in design or implementation that make future changes harder

Reading 10,000 lines of Python isn’t about judging others — it’s about training your eyes to see patterns that help or hurt long-term.

So: what pattern keeps showing up in your codebase, and what’s stopping your team from fixing it next time?

Written by Ahmad, sharing insights at @CodeWithAhmad

--

--

Code With Ahmad
Code With Ahmad

Written by Code With Ahmad

Full-stack engineer with 7+ years in Python, Django, React, and Next.js. Delivered 250+ projects for 100+ clients, from APIs to full web apps.