Dataclasses vs Traditional Classes in Python

One Python question I keep thinking about lately: dataclasses vs traditional classes. Python’s @dataclass decorator is great for reducing boilerplate. With one decorator you automatically get: • __init__ • __repr__ • __eq__ • other useful dunder methods So the code becomes much shorter and cleaner. But in practice, I often still prefer writing the traditional class with an explicit __init__ method. Not because dataclasses are bad — they’re actually quite elegant — but because explicit classes sometimes feel easier to reason about when working in larger codebases. For example: • the object initialization is immediately visible • you see exactly what happens inside __init__ • new engineers reading the code don’t have to mentally expand the decorator behavior Dataclasses definitely reduce boilerplate, but sometimes they feel like syntactic abstraction rather than a functional advantage. So I’m curious: Which style do you prefer in production code? 1. @dataclass for cleaner, shorter code 2. Traditional classes with explicit __init__ 3. Depends on the use case (DTOs vs business logic objects) Would love to hear how other engineers are using this in real systems. #Python #SoftwareEngineering #BackendDevelopment #CleanCode #Programming

To view or add a comment, sign in

Explore content categories