PHP vs. Rails

ziggy on 2005-06-12T13:14:03

David Megginson, a Java-head and long time markup guru, compares PHP to Rails, and finds that he likes PHP better:

[P]rototyping an app in PHP was like a cool breeze on a hot day. I wrote a few helper functions to automate escaping values to avoid SQL or HTML insertion attacks, but I managed to fight off the temptation to write a persistence layer in PHP. Instead, each page has some PHP code at the top that makes one or more SQL queries, followed by HTML markup with only minimal PHP added to insert dynamic results. It works, it actually seems scalable and maintainable, it’s easy to deploy (just about all ISPs already support PHP, so you just upload the *.php files), and debugging is trivial, because the query is right there on the page with the HTML that will display its results. Bugs are not buried deep beneath 20 layers of abstraction, and the database and filesystem are the only shared state.

Rails, on the other hand, was a disappointment. It tries to make my database invisible so that I think I’m dealing only with objects, but my database, and its query capabilities, are what will make my application more than just a collection of objects with a simple search box. I ran into a bug during one of the tutorials and it was almost impossible to trace the problem due to the deep layering. And the only thing that Rails seems to simplify is the basic CRUD operations, which are the easiest part of any web app. Rails also tries to tell me exactly how to set up my database and page hierarchy — I know that I can change it, but by the time I’ve learned to do that, would Rails still be any easier?


Either or

sigzero on 2005-06-12T17:10:46

I am neither in the PHP camp nor the Ruby camp but I would pick PHP over Ruby/Rails as well "IF" all I was doing was web applications. That is what PHP was built for and if you throw Smarty into the mix with PHP that is a very nice and easy combo for web application development.

Re:

Aristotle on 2005-06-12T20:48:13

It always makes me weary to see a lot of abstraction.

I’ve dropped Class::DBI in favour of hand-writing my SQL. Relational databases are not an object persistence layer; they are much more powerful than that. Class::DBI requires you to disregard any of your database’s capabilities that go much beyond flatfiles.

I am also reminded me of one of those REST vs SOAP rants I read a while ago, which said that the transport matters and that the URL is not just an endpoint to be abstracted away. Which is perfectly correct. I wish I could remember where I saw it (Google is no help).

Cf. Sam Ruby’s essay Reality is Corrosive.