Live data from Hacker News

OrmHate

martinfowler.com

71–80 of 136 posts

Re: OrmHate

#71
post #38

I think a lot of the frustration with relational databases in general comes from a misunderstanding. People conflate "relational" with "SQL", because of the historical accident that SQL is the most popular way to query relational data. Then when SQL isn't a good fit for their problem, they think relational is not a good fit for their problem, which is almost certainly not true. The original motivation for relational…

People conflate "relational" with "SQL", because of the historical accident that SQL is the most popular way to query relational data. Then when SQL isn't a good fit for their problem, they think relational is not a good fit for their problem, which is almost certainly not true.

For most practical purposes, SQL is the only way to query relational data. In the absence of alternatives, it's natural to conflate the notions of SQL databases and relational databases. I agree that SQL is a mess, but I don't think an approach based on pure relational primitives would make it better; in fact, I think SQL is a mess specifically because of lack of expressiveness in the pure relational primitives. NULL, ORDER BY, LIMIT/OFFSET, opaque keys, windowing functions, transitive closures, etc fit poorly into the relational model.

The original motivation for relational databases is to have path-independent access to data. This is a really powerful idea.

I agree with both assertions, but in many applications, path-based access makes the total majority of queries, and SQL or relational model provides little means to distinguish them from other equi-joins or arbitrary join conditions. In my opinion, it would be better to start with a navigational path-based database model, and extend it to allow constructing new paths dynamically.

Re: OrmHate

#72
post #59

The single biggest disadvantage of ORM for me is that in exchange for easier programability, they force you to learn a proprietary, arbitrary, ad hoc DSL that is less consistent, more complicated and less powerful than SQL.

It depends on what "proprietary" means. In Java, ORM is pretty much standardized with JDO/JPA.

or HQL. which is pretty much exactly what this guy means.

Re: OrmHate

#73
I think it's all about getting to know the tool (ORM) you work with. Look at the generated queries and their performance, use eager/lazy loading in the right places and mainly take care of the database operations that run most often. Switching to plain SQL might make sense if you don't need structured/hierarchical objects at this point in your application and a simple array/list/table will do just fine. Don't bother with that if your hand-generated query will most likely end up the same though. Use database-specific bulk imports or plain SQL if you have lots of data to insert and need it fast.

I am also often seeing comments about ORMs saying "What's so hard about SELECT..." - nothing's really hard about retrieving data, every decent developer will sooner or later end up with a working complicated SQL that gets them exactly what they wants. But I think the real benefits of ORMs start when you have to save/edit/update/extend relational data again and have to take care of all the inserts, updates, deletes across several tables, maybe including versioning or workflow (drafts or changes waiting for approval) and other additional complexity on top. That's the parts where I am glad to rely on an ORM supporting relationships and which can be extended via hooks or behaviours. (Note that I am mainly talking about 'Admin' pages here and nothing that runs too often.)

Re: OrmHate

#74
post #15

Earlier quoted context omitted.

> Those people who best understand the inherent object-relational impedance mismatch tend to be the very people who conclude that the effort isn't worth it. You're showing a severe bias. > I have found that ORMs are the most useful for the most trivial queries. That's really what ORMs are for. Three joins, max. Any more than that and you really can't trust the ORM. It's a computer, after all, not a DBA.

In other words, ORMs are at their most useful when solving the least challenging problems. To which we must ask: why bother?

>> In other words, ORMs are at their most useful when solving the least challenging problems. To which we must ask: why bother?

1. I disagree with your assertion. Ruby's ActiveRecord has scopes that make it very easy to compose complex queries from pieces; start with a simple query, then conditionally add clauses like where, having, joins, group, order, etc. I'm looking at code right now where mixing and matching clauses like that was crucial. It would have been a nightmare to do in raw SQL.

2. Even if you were right, "least challenging" != "least annoying." Washing clothes is a trivial problem, but I'm glad to have a machine do it. Same for writing the same boilerplate SQL 30 times a day.

Re: OrmHate

#75
post #43
post #26

Earlier quoted context omitted.

you are incorrect.

Yahoo's rationale for choosing PHP: "The short development cycles needed to stay ahead of the competition demand a web-centric scripting language that is easy to maintain and update." http://public.yahoo.com/bfrance/radwin/talks/yahoo-phpcon200... They didn't choose Python, or Ruby, or Java, because none of those languages are as expressive or shut-up-and-get-out-of-my-way as PHP. Just because a high schooler can wri…

PHP is more expressive than python, ruby, or java. I see.

Re: OrmHate

#76
post #39

Earlier quoted context omitted.

In other words, ORMs are at their most useful when solving the least challenging problems. To which we must ask: why bother?

I'm going to make an argument here, and you might disagree but that's fine: If you don't understand the purpose of an ORM, you haven't worked on a sufficiently large enough software project or don't fully understand what the definition of an ORM is. If you need to write a report of any fashion, do not use an ORM. You can help write the report with your ORM of choice, but at some point you need to get down to the lang…

But that doesn't require or imply an ORM. That's just a matter of having an object model.

Re: OrmHate

#77
post #56
post #40

Earlier quoted context omitted.

I strongly disagree with this. I'm consulting for a project where I cannot discuss technical decisions about database modelling; sometimes we need to query 20/30 tables or more in a tx, with very complicated mappings 5+ levels deep. If I was to write the sql for this, I'd take 10x the time and it would be wrong anyway. Of course, this is one end of the spectrum where the ORM just enable me to shoot in the foot faster…

"If I was to write the sql for this, I'd take 10x the time and it would be wrong anyway." SQL is the problem here. It's so hard to write reusable, composable fragments of SQL that we've all just internalized the idea that we have to write the query you're referring to from scratch every time, which is a bizarre and annoying intrusion of 1970s software engineering into our 2012 world. You almost certainly have pattern…

I've often felt that SQL was terrible, but I don't know what would be better.

Re: OrmHate

#78
post #3

"You have a relational mapping problem. 'I know', you say. 'I'll use an ORM.' You now have two problems." That just about sums up my experience with ORMs. Of course, like all things in the real world, experiences vary. However, I do think that generally, ORMs solve none of the difficult relational mapping problems and adds another layer of abstraction that complicates things like performance tuning to the point of ne…

Yeah. The mismatch between how devs expect to use the ORM, and how the ORM expects to be used, causes enough problems in my experience to make the ORM not worth it in the first place. I'm tired of seeing crazy-long NHibernate stack traces and exception descriptions because, like, a column got altered.

Writing data-retrieval code is tedious, and nerds always want to automate tedious things. But sometimes the cure is worse than the disease, and the effort to eliminate one type of tedium gives rise to a new, fancier kind of tedium.

Re: OrmHate

#79
He comes close but still misses the overall general issue and condition.

These are facts:

- Relational and/or heap representations can be fairly universally represented e.g. heap on FS aka VM

- "impedance mismatch" problem is peripherally about latency and more generally present regardless of heap/store (hey..) image representation medium

So in general:

Any in-memory store process that is distinct from an in-memory heap process will still face the "impedance mistmatch" unless

a) a compiler bridges the semantic gap between the two representation domains

b) a mediator provides an interaction means between the two distinct processes

A very specific case of this general condition is:

[in-memory object language runtime] [FS based relational DB]

Fundamentally the condition is that of 'networking' so the question immediately presents itself as to "what is distinct from general networking that is causing the tedium of mapping?".

Ad-hoc messages of potentially unseen semantics would certainly cause an "impedance mistmatch" in a networking setup. Think of the nightmare of infrastructure to do the boiler plate, etc. (Look familiar?)

So, queries are the raw nerve that is exposed by this type of coupling.

What is a query? What is (the meaningful consequences of) a query in context of heap and/or store?

A heap typically maintains a 'collected assembly of facts' e.g. a set of related objects (eternalban's comments trail collection object and various other data) all nicely stitched up by a static compiler and/or dynamic runtime. Same set of facts is distributed in a potentially unique manner across an unknown set of store media. A query in store is 'work'. It is also more precisely 'a functional computed in a specific time and space'. (CAP anyone?)

So we know the answers to each and every one of these adjacency issues in the simple form. The runtime memory object model process RDBMS is a very common system pattern that unfortunately exposes a whole truck load of these difficult interfacing issues in one lump scary form. It is a lot of 'work'.

What is necessary to get around this is entirely against the prevailing trends arguing for "simplicity" as this requires infrastructure level plumbing for code at the same level of care and attention as that given to analogous networks for IP.

tldr; ORMs (or any other magic layer) for independent actor system A-B coupling works best when the interaction patterns are bounded and statically known. Any increase in runtime uncertainties will necessitate working partially outside of the framework hand-holding and may even be more tedious. Choose your tools appropriately.

Re: OrmHate

#80
Throughout history there has always been some hate towards a platform that inherits and simplifies another platform. In truth, it would be more efficient to talk directly to the processor, but that takes a lot of time. And sure, ORM isn't the fastest way to data, but the deficit is well made up in the end result. You can't utilize ORM without an understanding of data. Suggesting that developers are leaving semantics behind is absolutely not true in most cases.
Post reply on HN