Re:Sqlphobia: The Irrational Fear of SQL
by mistermann on Sunday April 04, 2010 @09:59PM
(#1241188)
I can't think of a single article I've read with an anti-orm stance that has addressed what my issues are, and are successfully solved with an ORM.
For most ORM advocates, it is not a "fear" of SQL, it is a productivity issue. A good ORM gives you an entity model with inter-object relations, a powerful query language, in-memory object cacheing, and all sorts of other useful things, for free. They can be a huge productivity boost. And for those "what about this" scenarios that are always raised, a good ORM will allow you to easily drop down into calling native storedprocs when that makes sense. (This also applies to the supposed performance issue with ORM's)
I've read most of the anti-orm articles out there and I always get a disingenuous feeling from the author, like they are knowingly not being entirely honest.
A few other issues I've found with SQL:
- business rules or perhaps more appropriately, behaviours, when implemented down at the stored procedure level (which in a non-orm environment is exactly the proper thing to do) are largely hidden from the calling source code. So when reading the code, much of what is happening is not obvious unless one examines each SP. When using an ORM, this logic can be brought up into a higher level of your application making it much more visible and accessible.
- in large projects, every time you need a certain subset of data (filtered), or a different set of fields in the resultset, you end up writing yet another stored procedure, likely just for that task. Often, a stored procedure may already exist that would server your needs, but in a large project with multiple developers, how does one know of its existence, and even then, find it? I've found almost without exception that large projects start to degrade into a quite disorganized mess that is very hard to understand for a new maintenance developer. Of course, many of these problems can be avoided with proper organization and discipline, but the fact is in many places, they aren't. I find a good ORM largely prevents the problem in the first place.
For most ORM advocates, it is not a "fear" of SQL, it is a productivity issue. A good ORM gives you an entity model with inter-object relations, a powerful query language, in-memory object cacheing, and all sorts of other useful things, for free. They can be a huge productivity boost. And for those "what about this" scenarios that are always raised, a good ORM will allow you to easily drop down into calling native storedprocs when that makes sense. (This also applies to the supposed performance issue with ORM's)
I've read most of the anti-orm articles out there and I always get a disingenuous feeling from the author, like they are knowingly not being entirely honest.
A few other issues I've found with SQL: - business rules or perhaps more appropriately, behaviours, when implemented down at the stored procedure level (which in a non-orm environment is exactly the proper thing to do) are largely hidden from the calling source code. So when reading the code, much of what is happening is not obvious unless one examines each SP. When using an ORM, this logic can be brought up into a higher level of your application making it much more visible and accessible.
- in large projects, every time you need a certain subset of data (filtered), or a different set of fields in the resultset, you end up writing yet another stored procedure, likely just for that task. Often, a stored procedure may already exist that would server your needs, but in a large project with multiple developers, how does one know of its existence, and even then, find it? I've found almost without exception that large projects start to degrade into a quite disorganized mess that is very hard to understand for a new maintenance developer. Of course, many of these problems can be avoided with proper organization and discipline, but the fact is in many places, they aren't. I find a good ORM largely prevents the problem in the first place.