Live data from Hacker News

Zawodny: Database Abstraction Layers Must Die (at least for PHP)

jeremy.zawodny.com

11–20 of 25 posts

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#11
I don't know much about PHP abstration layers, but Django's ORM makes an app pretty damn portable from DB to DB. I know, without a doubt, that I could roll out my CMS/blog/documentDB in a heart beat to MySQL, Postgres, Oracle, and SQLite with nothing but a change to the settings file. I have to think that Django is by no means unique in this regard, and that PHP has the equivalent.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#12

Based on my experience, I do not agree with the author. DB Abstraction layer has helped me reuse the same libraries on different DB engines more than once. I had one occurance when I needed to install my new webapp in a hurry (for demonstration purposes) and couldn't arrange for a database with the server administrator fast. Well... I just changed "mysql" to "sqlite" in my DB config, fixed a few problems with SQL CRE…

I agree with you 100%. Smarty (or similar templating engines) can make it much faster to get a website up and running; as for the speed complaint, Smarty compiles it's templates to PHP the first time you run them, so there's really not much difference after that.

I'm also kind of tired of programmers who complain and complain about others taking the easy way out, people don't program like they used to, etc.; the whole reason for having abstractions is to take some of the 'real' programming out of the equation and let you focus on the actual task you want to accomplish. It may not be the most efficient method of programming, but there are only so many hours in a day...

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#13
post #11

I don't know much about PHP abstration layers, but Django's ORM makes an app pretty damn portable from DB to DB. I know, without a doubt, that I could roll out my CMS/blog/documentDB in a heart beat to MySQL, Postgres, Oracle, and SQLite with nothing but a change to the settings file. I have to think that Django is by no means unique in this regard, and that PHP has the equivalent.

Django pulls this off by being specifically designed to do it. There's a ton of code back there running for every query you execute, adding a tiny bit of overhead to everything you do, just on the off chance that maybe one day you might want to migrate to another DB.

That's certainly one way to go, and it makes sense if your product is a Framework intended to be used by thousands of developers on thousands of projects, many of which will require that kind of portability. If, however, your product is a product, then maybe it's not so important.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#14
post #11

I don't know much about PHP abstration layers, but Django's ORM makes an app pretty damn portable from DB to DB. I know, without a doubt, that I could roll out my CMS/blog/documentDB in a heart beat to MySQL, Postgres, Oracle, and SQLite with nothing but a change to the settings file. I have to think that Django is by no means unique in this regard, and that PHP has the equivalent.

I know this to be the case with Rails as well. I think his point about database portability has more to do with the data portability itself; obviously, if you switch databases, you presumably need to port all of your existing data to the new database system, including things like indexes, etc., and you may even have to do some new tuning work, since the new database system might have different ways of optimizing queries, etc. Now, admittedly, I haven't looked to see if there are conversion tools, but I wouldn't be surprised if there were things out there to ease a transition from one system to another. And in any event, so what if you DO have to do all of that...using a database abstraction layer will AT LEAST save you the time of having to go through your source and change a bunch of database system-specific calls.

Anyway, I just find his argument totally unconvincing.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#15
post #11

I don't know much about PHP abstration layers, but Django's ORM makes an app pretty damn portable from DB to DB. I know, without a doubt, that I could roll out my CMS/blog/documentDB in a heart beat to MySQL, Postgres, Oracle, and SQLite with nothing but a change to the settings file. I have to think that Django is by no means unique in this regard, and that PHP has the equivalent.

Django pulls this off by being specifically designed to do it. There's a ton of code back there running for every query you execute, adding a tiny bit of overhead to everything you do, just on the off chance that maybe one day you might want to migrate to another DB. That's certainly one way to go, and it makes sense if your product is a Framework intended to be used by thousands of developers on thousands of project…

Sure; but this is more of an argument against abstraction in general, vs. an argument against database abstraction in particular. If you use any kind of framework, since frameworks are made to be generally usable in many different situations with differing requirements, there's ALWAYS going to be stuff going on that you have no control over that you probably don't need for your project.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#16
post #10
post #6

Earlier quoted context omitted.

Yeah, I couldn't understand that either. He goes on saying "database abstraction layers" are bad but then, at the end says he uses a "library" that abstracts away database issues such as persistent connections, replication awareness and load balancing. How is that not a database abstraction layer?

The way I understand it the phrase "abstraction layer" is usually used to refer to the layer between your SQL and the database and is supposed to allow you to run the same SQL using multiple database engines (at least in theory). While the author's DIY library abstracts the database, I would say its main purpose is isolation, not abstraction. This makes it easier to port apps to new DB engines because it's not that h…

Yeah, I think he was more railing against "abstraction layers" that try and make calls to the DB look no different than the native language data structures.

His library is akin to separating the 'M' from the 'C' in MVC. He is saying that people go to the trouble of using these DB abstraction layers so they can proceed with spagetti coding the model (persistence layer in his terms) and the controller (business logic layer in his terms) together.

I'm not sure how valid that argument is though. Anyone I know that bothers to use an abstraction layer also separates the model from the controller.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#17
post #10
post #6

Earlier quoted context omitted.

Yeah, I couldn't understand that either. He goes on saying "database abstraction layers" are bad but then, at the end says he uses a "library" that abstracts away database issues such as persistent connections, replication awareness and load balancing. How is that not a database abstraction layer?

The way I understand it the phrase "abstraction layer" is usually used to refer to the layer between your SQL and the database and is supposed to allow you to run the same SQL using multiple database engines (at least in theory). While the author's DIY library abstracts the database, I would say its main purpose is isolation, not abstraction. This makes it easier to port apps to new DB engines because it's not that h…

I suppose. But abstraction layers give you so much more than that. A good counter-example for why you should use one is simply prepared queries. Doing stuff like:

mysql_query("SELECT something FROM table WHERE that='" . mysql_real_escape($var) . "'"); is just terribly ugly and annoying, especially if the query gets complex.

I've never put any faith in the whole database portability claim for exactly the reason he points out. Any even moderately complex app is going to leverage database-specific performance enhancements that can't be abstracted away.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#18
So why do folks [make templating systems like Smarty]? Because PHP is also a programming language and they feel the need to "dumb it down" or insulate themselves (or others) from the "complexity" of PHP.

I don't think that's it, or if it is, it's not a very good reason. Using a templating system that's less than a full programming language keeps you from putting too much logic in your templates. Most of us prefer that logic and presentation be separated. PHP's HTML embedding tempts people to do the Wrong Thing in that regard.

Re: Zawodny: Database Abstraction Layers Must Die (at least for PHP)

#20
post #18

So why do folks [make templating systems like Smarty]? Because PHP is also a programming language and they feel the need to "dumb it down" or insulate themselves (or others) from the "complexity" of PHP. I don't think that's it, or if it is, it's not a very good reason. Using a templating system that's less than a full programming language keeps you from putting too much logic in your templates. Most of us prefer tha…

But along this line - PHP started as a template language... and it should have remained a template language.
Post reply on HN