SQL is a DSL

Sometimes it seems like programmers will do everything to avoid SQL. At the same time DSLs (Domain Specific Languages) are very popular. If DSLs are so great, why are you trying to avoid SQL? Or procedural extensions to SQL? SQL is a DSL for dealing with relational data.

SQL was invented to deal with relational data, there aren’t many better, easier and faster ways to deal with large amounts of data stored in a relational database. Seriously, databases are made to handle large amounts of data. To sort it, to filter it, etc. Trying to do that in another language, or even worse, in another layer, makes no sense. It’s really expensive to move the data from the database into your middleware layer, and Java (or any other middleware language) isn’t really a good language to sort and filter large amount of data.

Procedural extensions to SQL, like for example Oracle’s pl/SQL, are even worse off. It seems like middleware programmers will do everything not to have to use a procedural language in the database. But fact is that pl/sql is a very good tool to write data heavy business logic in. There is no faster way to handle large amounts of data, then right there in the database. And there is no easier way to write data heavy procedural code than using a procedural extension to SQL. That is what pl/sql is: a DSL for writing data centric logic.

Added bonus: anything in the database is extremely reusable. Almost every language has a library which allows you to make use of relational databases. So, if you put it in the database, no matter what middleware or frontend language you’re going to use in the future, your data centric logic can be reused.

blog comments powered by Disqus