Why are Developers so Afraid of SQL?
Dustin Marx has blogged about a phobia unique to the software industry: sqlphobia.
Marx does not suffer from this phobia. His
ability to read SQL has proved useful in debugging problems with
code that uses JPA implementations. But, he perceives a great, and
to him unnecessary, effort to hide SQL from the developer. This
takes the form of tools such as Enterprise Java Beans – or, “SQL
made worse by embedding it in XML,” as he puts it – Hibernate, the
Spring Framework, Java Data Objects, object databases, and XML
databases. But, the biggest offender in this perceived SQL
cover-up, is object-relational mapping (ORM) tools.
There are some ORM tools that Marx approves of. He defines
himself as a fan of Java Persistence API (JPA) but finds that on
occasion the impact JPA has on the object design is too
heavy-handed. This isn’t his only bone to pick with JPA: “there are
situations where even the best ORM implementation introduces more
trouble and requires more effort than using SQL directly.”
So, if all these tools are often unnecessary and sometimes even
detrimental, how does sqlphobia start? Marx sees it as a fear of
the unknown, something which he has had personal experience of. He
failed to learn SQL in college, and was subsequently hesitant to
use SQL in his first job. Then, he was put on a project where he
used SQL on a regular basis, and he quickly grew used to it. He
sees this fear in others, and views it as irrational because the
mappings supposed to cover-up SQL, are often more difficult to
maintain than SQL itself.
He acknowledges that SQL is far from perfect. To his way of
thinking, a standard is only as good as its implementations, and
the most common SQL implementations poorly implement the standard
or ignore it altogether, which means SQL is pretty much lacking a
standard. This lack of standardisation only plays into the
aforementioned fear of the unknown.
Although SQL requires the learning of new syntax and semantics,
Marx actually sees a benefit to this. Once you have learnt SQL,
writing a database access piece of code in a new programming
language is easier, as the familiar SQL language provides a
commonality to lean against. And, if that isn’t enough to get you
learning SQL, Marx points out that it is one of the most commonly
occurring languages in a programmer’s overall career. When he
phrases it like that, it does make sense to take the plunge and get
familiar with SQL.
Marx does fail to mention portability problems surrounding SQL,
but he does have a valid point in that removing any anxieties
surrounding SQL would have a beneficial effect on certain projects,
as it allows the developer to “make the correct choice for the
situation.” In a sqlphobia-free world, if a project would benefit
from using SQL without an ORM, then the developer would use SQL
without an ORM. Wasting time shoe-horning a non-SQL solution into a
SQL-shaped hole, is only going to damage a project.