Tuesday, April 19, 2011

After all, ORM might really be the Vietnam of Computer Sience ...

The best DSL I've ever seen for working with data is SQL.
- Rob Conery, Thoughts on WebMatrix

The last mile is what kills object-relational mapping. Rails ActiveRecord does not try to go the last mile.

Abstracting SQL often isn't a good idea from my experience
- @codemonkeyism on twitter

Monkey thinker I have a high opinion of StackOverflow. What they accomplished in a very short time is amazing.

Reading the news that StackOverflow is writing its own object-relational mapper made me think ...

As a consultant I have seen almost no project that did not run into troubles with their ORM infrastructure at some point in time ...
... so maybe Ted Neward was right when he claimed that ORM is the Vietnam of Computer Science more than five years ago.

I cannot make my mind up on this one...

On one hand, I am a big fan of ORM. I am regularly teaching JPA.
On the other hand, I am tearing my hair out, again and again, fighting with ORM frameworks, trying to persuade them to do what I actually want (usually having a very clear idea what I want but having to shave yaks to get there, while in most specific cases it would be easy to just write the SQL I want).

Maybe it is the ORM frameworks that are the problem?

For advanced usage scenarios it often feels like ORM frameworks are adding a lot of accidental complexity.
But then again, I think ORM itself represents an essential complexity that always surfaces one way or another... sooner or later ...

The ORM-Vietnam-Hypothesis talks about quick initial successes and the Law of Diminishing Return.

Now here are some interesting questions:
  • How valuable are the initial successes?
  • How long lasts the phase of initial successes?
  • How can you prolong this phase?
  • How can you reliably detect that the law of diminishing return kicks in?
Screen shot 2011 04 06 at 8 24 32 PM
Is it possible to somehow leverage the phase of initial successes and then stop at the right moment and turn to a better solution without loosing all the initial sucesses?

Is that what StackOverflow is doing, turning away from Linq2Sql now, going for a custom ORM solution?

StackOverflow started in 2008 and has gone through an amazing evolution since.
They started with a very simple programming stack and very modest hardware, with only some part-time programmers (as far as I remember from the Hanselminutes podcast). Yet they were able to create a product that influenced the live of most modern programmers...
To achieve this, they had do choose the most pragmatic solutions. I guess Linq2Sql was the obvious choice ...

Would StackOverflow be better off if they started with their own ORM implementation from the bginning?
Probably not ... I guess they would be at the same point now: They would have to rewrite it today based on their real world requirements and their experience from the last 2 years.

It seems that this leads us back to the principle that Premature Optimization is the Root of all Evil...

Could this be a general advise: ORM frameworks being there to get you off the ground easily, but prepare for a rewrite later, at least for some parts of your application?
Don't invest too much in your ORM infrastructure, so that you can't turn your back on it once the Law of Diminishing Returns kicks in?

... and how to achieve this efficiently?

While I was writing this post Hanselminute 262 was published, interviewing Sam Saffron and Rob Conery about their Micro-ORM implementations Dapper and Massive.
Interesting ... Micro-ORMs as the shiny new thing between the overblown swiss-army-knife-style-ORM and the not-invented-here-do-it-yoursef-style-ORM?
The podcast also talks about the fact that a simple "in-line" style of writing apps with fewer abstractions is becoming stylish again ... right the style we condemned and tried to get away from 15 years ago... and how this is related with a modern "getting things done"-mentality ... very interesting indeed.


  1. Imho the problem with the "big fat" OR-Mappers (Hibernate, EF) is, that they give you the illusion, that you can abstract from underlying relational model and allow you to think in an object oriented model.
    This new, light mappers (are they OR-Mappers at all or is DAL a better description?) don't even allow you think only in an OO model.
    What i still don't get after all these years: Why have the OODBs disappeared?

  2. @christoph

    Yet in most "non-trivial" projects I have seen, that had a "real" domain model represented in code I, the mapped entities were not the domain model.
    In these projects the mapped entities are used to provide persistence to the domain model, and there was another "mapping" implemented... and that could be the scenario where the light mappers are shine.

    Hope you are well over there :-)

  3. This is my experience with home made ORMs. A clever guy comes up with an ORM framework, company implements a critical component using his framework, he becomes a celebrity. The company hires new developers but clever guy is too busy to explain his masterpiece or realize what was brilliant in his own mind is too damn difficult to explain or document. New guys secretly bad mouth the framework - project sees little progress.

  4. You know the US _lost_ the Vietnam war, right?

  5. Stop mucking about with ORMS. You can get the same results with MyBatis (formerly known as iBATIS).

    And it has tools (probably news to you) to get you up and running quickly.


  6. @Anonymous

    Yet another silver bullet?

    Furthermore. XML is like violence. If it doesn't solve your problem, you're not using enough of it.

  7. @jbandi Good post, btw.


Related Posts Plugin for WordPress, Blogger...