ORM vs. SQL, compared to C vs. ASM

History is repeating itself. This is nothing new, but it takes wisdom (and Elephant memory) to remember when and how things had already happened in a similar way. When you feel that the whole SQL versus ORM debate is a bit boring and you may have seen it before, you’re probably right. It’s another religious war that can be compared to the war between C and Assembler some 40 years back. Think about it this way:

ORM vs. SQL

How many ORMs do you know that support:

  • Window functions
  • MERGE statement
  • Recursive queries
  • Common table expressions
  • Ordered aggregate functions
  • Statistical functions
  • Stored procedures (And I mean not just scalar ones!)
  • SQL-based XML
  • Temporary tables
  • … I could go on and on

ORMs are not just “higher-level” they are an entirely different paradigm, put on top of SQL. So, saying SQL is “lower-level” is not entirely accurate. It’s on a “different level”. ORMs are pretending that SQL is just a little “low-level” thing.

C vs. ASM

(citing reddit user henk53)

Which C compilers at the time made use of:

  • Advanced addressing modes
  • Opcode tricks
  • Special instructions (intrinsics came much later)
  • Jump tables (yeah, switch is close, but not quite it)
  • Build-in high level functions on some architectures (like string copy)
  • Page zero tricks
  • Segments (ugly things when all you have is small ones, but quite powerful when used fine-grained for ‘objects’ and structures)
  • Delay slot shadowing
  • Knowledge of fitting computations exactly in registers and L1.
  • … I could go on and on

C wasn’t just higher level, it was another paradigm, and yes, C compilers pretending that assembly is just a little “low-level” thing did raise our hackles back then. It threw away all the nice subtle intricacies of each specific CPU architecture and made them all equal by using only the common denominator of functionality that each CPU had.

It took a while, but eventually C compilers got better at optimizing than humans and could actually take advantage of advanced instructions in a CPU.

Original discussion

See an extract of the original thread here:
http://www.reddit.com/r/java/comments/sk25o/forget_hibernate_jooq_is_byfar_the_best_database/#c4f6z1w

3 thoughts on “ORM vs. SQL, compared to C vs. ASM

  1. Some have argued (and I tend to agree) that SQL and the relational model are actually higher level of abstraction than the OO interface an ORM adapts them too, and that this is one of the fundamental drawbacks of using an ORM. So its a different paradigm, as you point out, but also the reverse of the C / assembly analogy. Just as a line of C translates into several assembly commands, you could typically write a single SQL statement to do something done by many calls to your OO interface.

    1. That’s an interesting point of view. I tend to agree with you, but eventually it will be history to teach us about the truth.

      Think about functional programming. Many languages already have it, Java 8 will have it too, to some extent. I’ve recently posted a link about Java 8’s Streams, which will allow for great expressiveness, still within the OO domain:

      https://blog.jooq.org/2012/04/19/exciting-ideas-in-java-8-streams/

      We’ll see where this all leads us…

Leave a Reply