3 ms·
realise that ORMs are inherently stupid. That's quite the claim... Care to expand on why you think ORMs are "inherently stupid"?
by mindcrime 13y ago
realise that ORMs are inherently stupid.
That's quite the claim... Care to expand on why you think ORMs are "inherently stupid"?
- tel 13y agoI think ORMs are "inherently stupid" (or: "quite likely to be leaky as abstractions") because they don't necessarily share a theory with the underlying databases ("something like but not exactly relational algebra") and I don't think many people spend time proving that the OO-like theories can be properly embedded into something-like-relational-algebra. Not saying you can't get work done with them, but it does mean that they're likely to leak.
- sjwright 13y agoBecause you can't cleanly map objects to sets nor sets to objects. Sure, if you want to pretend an RDBMS is an object store you certainly can, but you'll be forced to have an incredibly stupid schema, and will miss out on much of the benefits of a good RDBMS. Turning a powerful SQL database engine into an object storage emulator is just sad. If your underlying data suits objects better than sets, consider using something that's designed for the job, like one of the many non-SQL database systems. Although it may seem trite to say it, Object/Relational Mapping is the Vietnam of Computer Science. It represents a quagmire which starts well, gets more complicated as time passes, and before long entraps its users in a commitment that has no clear demarcation point, no clear win conditions, and no clear exit strategy. http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Compute... Well worth reading. Also: http://database-programmer.blogspot.com.au/2010/12/historical-perspective-of-orm-and.html http://database-programmer.blogspot.com.au/2010/12/historica... http://www.codinghorror.com/blog/2006/06/object-relational-mapping-is-the-vietnam-of-computer-science.html http://www.codinghorror.com/blog/2006/06/object-relational-m...
- jpatte 13y agoUnfortunately I didn't have time to read these articles in depth, nor do I have the time to write a detailed answer now - sorry. But it seems to me that the situation has changed since these articles were written, at least concerning the tools I know best (which are .NET and C#). We now have built-in support for data (sets) manipulation in C# and Entity Framework makes things like db.Customers.First().FirstName with syntax support totally real. Many of the premises these essays seem to be based on (like "the languages in play lack any real specialized data structures") are just not true anymore. Also, I would like to know more about why using an ORM like EF would force me to "have an incredibly stupid schema".
- mindcrime 13y agoTurning a powerful SQL database engine into an object storage emulator is just sad. Now that I can agree with, but I would consider that to be a (subtly, perhaps) different position than: "ORMs are inherently stupid". IF you have the option of choosing a native object store for persisting objects, then - by all means - choose it. But in cases where an RDBMS is the data store of choice for whatever reason, and you still have to store your objects there one way or another, I'd prefer using an ORM like Hibernate over hand-rolling all the low-level SQL/JDBC code to marshall objects back and forth between the DB.
- deleted 13y ago[deleted]
- orclev 13y agoalso without an ORM do you just hand roll all your object graphs? I'm picturing a sea of builders and factories which amount to a hand rolled ORM anyway. Or are you practicing stringly typed programming? Ultimately in any strongly typed language you're either going to make/use some kind of mapper or else abandon typing and use maps/dicts which raises the question of why you're using a strongly typed language in the first place.
- wtetzner 13y agoFirst, you can have strongly typed languages that aren't object oriented. Instead of using maps/dics, you could use records. The thing I don't like about ORMs as they are typically handled is that you map objects to tables up front, and those are the things you can query for. Using something like Linq, you can more easily treat your database as relational, and still return strongly typed objects. These objects can be the thing you wanted to return from the query, which is not necessarily mapped directly to the entities in the database. I like this approach more, since you still get one of the main advantages of a relational database: you can get the data in the shape you want, not in the shape it's stored.
- camus 13y agomost ORMs have a query language too, it's not just "Linq". Orms are good for development purposes and you can always do raw SQL queries within ORMs at some point.
- wtetzner 13y agoThe thing that's nice about Linq is the integration. You can directly reference variables in the things you're querying, and then either fill in an instance of an existing class, or generate an anonymous object. For example: var query = from c in customers join o in orders on c.ID equals o.ID select new { c.Name, o.Product, Address = c.MailingAddress }; Of course, anonymous objects in C# can be a pain in the ass, since you can't usefully return them from a method. Something like Scala's structural types would solve that problem. I don't really like C# that much as a language, but I do like the Linq approach.