PHP vs Ruby on Rails, Part 1
Over the last few weeks, I’ve been asked by both friends and clients, “So what is that thing called Rails I keep hearing about (and/or keep hearing you talk about)? How is it different from PHP?” Typically I give them a three-part answer that’ll I’ll now iterate for the blog. While this is far from a complete comparison, hopefully it will be useful to some people out there. The first thing to keep in mind when trying to form a comparison between PHP and Rails, is that PHP is just a language. It’s a scripting language that has a lot of useful functions that make adding dynamic content to web pages easier than its predecessors. What PHP is not (and what Rails, in fact, is) is a framework. In software terms, frameworks are generally tools and pre-built objects that help you create a solution faster by not reinventing the wheel.
More specifically, Rails is a full-stack framework. Full-stack basically means that when you decide to use Rails it will provide practically all of the tools necessary all by itself. While you are welcome to use other tools for sections of Rails’ functionality, most current Rails developers are not (and for obvious reasons described below).
So PHP is just a language. When you choose to use PHP to build a significant web application what you’ll want to do is look for tools and pre-built objects that are written in PHP. Some are packaged together in frameworks. Other times you’ll assemble them ala cart (a database abstraction layer here, a template system there). Sometimes building systems this way makes a lot of sense, but other times the overhead of divided tools makes for more work than it might be worth.
In Rails, they follow a mantra of “Convention Over Configuration.” With this in mind, Rails will follow industry conventions to make your job easier whenever possible. One example where you can see this in action is with page templates.
In Rails, if you have, for example, a BlogController and it has a method called list, Rails will automatically use the list.rhtml file inside of a folder called blog in your views folder. Not only that, but Rails will automatically pass on any instance variables you were using in the controller so that the view has access to them.
Now, when I am doing something similar in my own PHP apps, I have to manually instantiate the template object, manually pass references to any variables I know the view will be interested in and then manually tell it what template file to use. While all that manual code is pretty simple and easy to write, on even medium-sized apps it starts to take a toll on the leaness of the codebase.
This is one of the many reasons I like Rails. It will follow obvious conventions when possible but allow you to override the convention with a specific command; in this case to use a template file other than list.rhtml if needed.
Conclusion for part 1: PHP is just a language. Rails is a full-stack framework. PHP has lots of useful tools; they just don’t gel as well and usually require more configuration.
Part 2 will be posted soon. In it, we’ll look into the Ruby language and how it differs from PHP.
Update:: Part 2 is now online!
Posted on: December 24, 2005 – 12:36 pm


22 Comments
Here is my take on the subject, why I think PHP may win out despite rails superiority, webdevchron.blogspot.com
is this in ruby?
Yes, this whole site is in done Ruby, more specifically Rails.
Wonderful article distinguishing PHP and Ruby. Its really gud. What about image-processing in ruby? Like we have GD in php! Is there any ruby specific libraray available? Please comment!!!
To Deepak: A popular soultion to image processing is rmagick:
To Mike Zornek : hi Mike, I have seen the link you supplied for imagemagik. its reallty wonderfull if i have imagemagick or rmagick integtated with ruby as it offers almost all effects which photoshop offers. thanks and regards, deepak
Hi Mike!
I have just installed ruby on rails on my computer sucessfuly! But em bit comfused where and how to start building web applications. Actually i followed one good tutorial on configuring ruby and its wotking here. I have installed few webpages written Ruby and they are also working. Add/insert/update is all working fine. But the only problem is em unable to locate the files which produces this webpges. Em a PHP developer and using Ruby for first time and also very much interested in learning and working in ruby. Also suggest me if there are good books on Ruby. Please help. Your prompt reply shall be highly appericiable. Once again thanks and regards, Deepak
The book I like to recommend is Agile Web Development with Rails. I buy the PDF+Print combos from those guys and love it. The print is great for reading through the whole book from the couch and then the PDF comes in handy for reference.
Best of luck getting started with Rails.
Hi mike!!!
thanks for the prompt reply and ur suggestions. Could you please do one more favor?? I mean please send me the the PDF version of the same book if possible or otherwise i will have to purchase online.
Thanks and regards, Deepak
Hahaha. You’re kidding right. He’s not gonna give you the ebook. however if you goto http://www.ebooksportal.org you’ll find it there and a lot more too.
Hello, em just about to purchase the books online. But i was expecting a short reply from you mike. anyways bro. i have lots of books on php, please command me if u need any of them and i will forward you just like anything. Take care bro. Bye Bye ANGREZZ
Yeah, sorry. No I’m not going to post my PDF you’ll have to buy your own.
Hello!!
Thanks for replying. and i would like to tell you that i have got the same ebook on RoR and its really fantastic. I would like to say thank to you. Thanks for the great suggesstions and all that. Take care and b bye
Very nice comments a about the states of the languages. Maybe you could comment on how portable Ruby code is versus Php. I know they’re both interpreted languages, but I’ve seen numerous Php apps that you can deploy on your own network easily and haven’t seen that many Ruby ones yet.
Dear Mike,
I am from India. I was more than happy to read this blogs of Ruby on Rails. I was looking for a start, which you prpvided in a simple yet effective way.
I would appreciate a little more support from you.
(1) Could you kindly put some links pof hosting providers for Ruby On Rails, which you think are reasonbale and good.
(2) Could you kindly place links to few starterkits ( ready made little websites ) with source codes for learning purpose.
(3) Good list for few IDE tools, just like dreamweaver, expression web or Visual web developer, which are really great in creating wesites with Ruby easily and quickly.
This few information will really give a boost to new developers like us.
Thanks
Paraag P Kantharia
You can read about our take at our blog.
PHP has a framework. http://framework.zend.com
pls refer to following ads http://www.youtube.com/watch?v=n1NVfDlU6yQ http://www.youtube.com/watch?v=Ld919lziKgE http://www.youtube.com/watch?v=GQXqWkWqnSw
Sorry but this post is a bit crappy. Why you compare Ruby Framework to PHP language? Why don’t you compare other frameworks like Symfony, Cake, Prado, Zend Framework to Rails? Or why don’t you compare Ruby with PHP? Those would be far more true than compering framework to language.
Isn’t it a bit silly to compare PHP to Rails?
Compare PHP to Ruby, and compare, say, symfony on PHP to Rails on Ruby :)
That’s rails on ruby, ruby on rails is just funny :)
wow cool site dude 10x ;) see u zoo animal sex tube
great work man thx
Post a Comment | Comment RSS feed