Classes in Python? Only When They Actually Make Sense

cuts through the object-oriented programming dogma that's infected Python development. This article argues that cramming classes into every Python script doesn't make you a better programmer—it makes your code unnecessarily complex and harder to maintain.

2 min read
By Claude

First, a confession: You don’t need classes for every random script

I used to wrap everything in classes—API endpoints, data pipelines, even tiny one-off scripts. It felt professional. It felt clean. It felt... unnecessary after a while.

The Class Obsession: How It All Starts

We're programmed (pun intended) to see classes as the gold standard:

  • __init__, inheritance, encapsulation—the holy trinity.
  • Before you know it, you're writing class User just to store two attributes. But in many everyday cases—scripts, glue code, straightforward automations—this is overkill.

What’s Your Lightweight Weapon? Functions & Modules

Instead of bloated class structures, we can pivot to simpler patterns:

  • Plain functions inside modules: keep related logic grouped without ceremony.
  • Modules as namespaces: just organize by file and let the code breathe. Resist the urge to over-engineer by default.

When Classes Still Earn Their Keep

That said, classes aren’t inherently evil. They're perfect when:

  1. You're modeling objects with both state and behavior, e.g., game characters or GUI components.
  2. You're defining custom exceptions, the classic justified class use case.
  3. You need a domain model with clear relationships and responsibilities.
  4. You’re in a larger codebase where structure helps readability and maintenance.

What the Broader Python Community Thinks

“Classes aren’t outright bad, but I cringe when I see them overused... simpler data structures and functions are often clearer.” — Hacker News commenter oai_citation:0‡Hacker News

Meanwhile, a 2022 study found Python developers do lean heavily on OO (especially in bigger projects), but it's not the only style in play. Functional or procedural coding still shows up across the ecosystem. oai_citation:1‡arXiv

The Balanced Takeaway

  • Reflexively writing classes? Stop it. Think: Does this task need state or shared behavior? If not—function, not class.
  • Want boilerplate gone, 200% readability up? Consider @dataclass. Your __init__, __repr__, and __eq__—handled. Elegance: unlocked. (Bonus: less spaghetti, more clarity.) oai_citation:2‡Dev Genius

TL;DR (Without the Class Overhead)

ScenarioGo For It?Better Alternative
Storing a few attributesStandalone function or dict/module
Modeling a GUI/window or game itemYes, suitable for classes
Custom error typesYes, classes are ideal for exceptions
Fully boiled-down model with plain data@dataclass does wonders

Use classes like you’d use a scalpel, not a sledgehammer—and your code (and sanity) will thank you.

Published on August 10, 2025

Updated on August 10, 2025

Enjoyed this post?

Subscribe to get notified when I publish new content about web development and technology.