HN
Today

What ORMs have taught me: just learn SQL (2014)

This 2014 post argues that Object-Relational Mappers (ORMs) often create more problems than they solve, contending that understanding and directly using SQL is ultimately more efficient and less frustrating. The author highlights common ORM pitfalls like inefficient queries and complex schema management. It remains a perennially debated topic on Hacker News, underscoring the ongoing tension between developer convenience and database performance.

8
Score
2
Comments
#3
Highest Rank
3h
on Front Page
First Seen
Jul 4, 3:00 PM
Last Seen
Jul 4, 5:00 PM
Rank Over Time
5316

The Lowdown

The author, reflecting on 30 months of database interaction with Postgres/SQLite and ORMs like SQLAlchemy and Hibernate, concludes that ORMs are often more detrimental than beneficial. While they can augment SQL, they shouldn't replace it, as their complexities frequently necessitate deep SQL knowledge anyway.

Key issues highlighted include:

  • Inefficient Data Retrieval: ORMs encourage a SELECT * mentality on "wide" tables, leading to excessive data transfer and complex joins. Generating efficient queries, especially with advanced SQL features like window functions, becomes cumbersome, forcing developers to either write SQL or do more work in application code.
  • Dual Schema Management: ORMs introduce redundancy, requiring data definitions in both the database and application. Managing DDL and schema migrations becomes complex, with the author preferring a database-first approach and queries as the database's API.
  • Identity Challenges: The impedance mismatch between application object identities (memory pointers) and database identifiers (primary keys) creates a "leaky abstraction," often requiring manual intervention to synchronize.
  • Transaction Complexity: ORMs don't inherently simplify transaction management. Developers still face the challenge of handling dynamically scoped transactions, leading to boilerplate and modularity issues.

Ultimately, the author advocates for viewing the database as a data type with queries as its API, rather than merely object storage. They even reconsider the wisdom of rejecting stored procedures, concluding that direct SQL knowledge is essential to avoid the "ORMs make it easy" trap.