Live data from Hacker News

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

woz.posthaven.com

111–120 of 360 posts

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

#111

Earlier quoted context omitted.

> ORMs are bad, because objects aren't particularly useful to deal with most data. Objects are containers of data; that's a crazy statement to make. The relational structure maps pretty cleanly to objects, properties, and collections. However, objects are not good for reporting. And the author mentioned doing 14 joins and hundreds of columns - that smells like a reporting query.

The relational structure maps cleanly to badly designed objects, where most classes have 5-10 fields and most fields are opaque data values with setters and getters. If you wrote classes like that in isolation, you'd have to do some serious work in code review, explaining why a hodgepodge collection of properties is a single unit of responsibility. But I've never worked in an ORM-using system where they weren't endem…

I don't buy into the idea that those kind of classes are just unqualified bad design. The majority of applications exist to merely to store information entered by users. Using a class to hold that data in a structured and type-checked way is perfectly reasonable.

And they aren't a hodgepodge collection of properties; they're entities that represent a single item in a system whether that be a person, a widget, an order, or a product.

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

#112
post #107

Earlier quoted context omitted.

Ok, let’s break this down: > Good ORMs are there to automate the repetitive tasks of composing largely boilerplate DML statements, facilitating query composition, providing abstraction for database-specific and driver-specific quirks None of that requires an ORM. A simple query builder will suffice and it will be much easier to debug and much less error prone than an ORM. > providing patterns to map object graphs to…

> A simple query builder will suffice and it will be much easier to debug and much less error prone than an ORM. What's the difference? To me, an ORM is largely a query builder.

Is it a good one, though?

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

#113
post #108

Earlier quoted context omitted.

LINQ isn't a ORM. I assume you mean Entity Framework? EF definitely has the foreign key issue. We have around a thousand tables, we tried to generate the classes for all of them including foreign keys, problem is that when you create a context that references even only a single table, it will load everything that is foreign keyed including siblings of siblings of siblings, until you run out of memory. Only way around…

Were you doing serialization or something like that that recursively accessed all of the properties in the model? If so, and if lazy loading was turned on (the unfortunate default) then the serializer would indeed keep exploring the object graph until it either loaded your whole database or hit OOM. That's about the only scenario I can think of that would cause such an issue - EF doesn't eagerly load related entities…

Sounds like they're actually referencing some of the well-known query-generation issues in EF, though giant queries and long generation times are more common manifestations than OOM, which seems to be an extremely pathological case.

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

#114
post #85
post #78

Earlier quoted context omitted.

How were those relations represented? If I understand correctly, you were not just wrapping tables in a database, but using some other backing implementation. What were the most common operations, and what was the performance like?

Oh, the implementation was fairly straight-forward. I think just sorted arrays are something. It wasn't about speed of execution, but expressiveness when coding. Later on they even added proper type system support. Common operations were things like map/project, extend, filter, join, collect-by-key / expand, etc. Just as Codd pointed out in his original papers, relations allow you to not have to make a choice about a…

> Just as Codd pointed out in his original papers, relations allow you to not have to make a choice about a hierarchy for your data.

Or, alternatively, make it really painful when you do actually need to query hierarchies, along the lines of "give me all the tuples above this one in the hierarchy".

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

#115

(Bias: I'm one of the Hibernate ORM committers.) Hibernate (and presumably any ORM) was never intended to be a complete abstraction of anything-SQL. Like others have mentioned here, an understanding of SQL must be had before using an ORM. The ORM is one piece to the puzzle, not a shield to prevent you from having to touch SQL. One pattern I typically use is a take on CQRS: Hibernate for writing/updating/fetching/dele…

I'm so glad someone finally confirms my idea about using hibernate. I've been in constant battle with developers that map full object graphs coming Frome some endpoint to hibernate/jpa annotated classes and then throw it at hibernate. Here you save this... It just doesn't work that way very well. It's always a mess with relationships. Whereas you run your logic on entities attached to the session things work out nicely.

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

#117
post #82
post #77

Earlier quoted context omitted.

LINQ is not an ORM. My examples were showing easy, lazy evaluation. My C# is rusty, but the examples mostly hold I think. The following gets executed on iteration (of expensiveOrders), the lambda is compiled into a Function and run on each item in orders: IEnumerable orders = ...; const expensiveOrders = orders.Where(o => o.total > 100) The following gets compiled into an expression tree, which an ORM can analyze and…

Thanks. My quip was just that objects (as in object-oriented-programming) aren't the right abstraction. Having some kind of mapper in your language between the database and the entities your program is dealing with is useful, and you showed that functional programming is a more friendly host than oop. (Logic programming might also be workable?)

Objects are fine, it's classes that are often limiting. Consider the very first example above (corrected to be valid):

   var r = customers.Select(c => new { cust = c, orders = c.Orders })
This gives you an IEnumerable (basically, a forward-only sequence) of objects - but these objects are of an anonymous type that was implicitly defined by "new".

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

#118
post #71

Earlier quoted context omitted.

The DSL for your database is called SQL.

This is a quip that misses the parent's point. SQL isn't very composable, because its syntax requires infix notation, position-dependent phrases, separators, and the like. The abstract syntax tree of SQL is much more valuable than its syntax, which is essentially just a bad English serialization that resembles a natural language sentence. A DSL which manipulates queries and then produces syntactically valid SQL is tr…

SQL is composable if you use views, just create a view for anything that you want to reuse in multiple queries.

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

#119
What's the current state of object-oriented databases? Any progress since good old Gemstone? Why was Gemstone unsuccessful? Cost? Performance? Tie-in with Smalltalk? Is there any promising OODB being used these days? Because now that would take care of the OO-relational impedance problem.

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

#120
post #107

Earlier quoted context omitted.

> A simple query builder will suffice and it will be much easier to debug and much less error prone than an ORM. What's the difference? To me, an ORM is largely a query builder.

Is it a good one, though?

Probably better than the one I could build by hand, with far better documentation, and greater ease in googling problems :)
Post reply on HN