Why is Ruby on Rails better than PHP?
Written By HRJamie on Sep. 29, 2006.
35 Comments
Report Note
+ Clip This
Disclaimer: I am NOT a developer. At best, a product manager. Definitely an experienced internet entrepreneur. But not a programmer unless you count brief stints with BASIC, REXX (points to anyone who's coded in it), VisualBasic, and a slight LISP (ha).
I've been trying to explain to VC friends and other Web entrepreneurs why Rails is superior to PHP. Back in the day, we coded our first e-commerce platform in PERL. I know that's old-school among the 9rules audience (we listened to CDs back then, too), but can someone explain why Ruby on Rails is better than PHP?
Here are a few things I've learned:
1 - Rails can handle search-friendly URLs. No more ?source=@@@HRJamie.
2 - Rails is the hot Web 2.0 technology. (Our office is a block from Adaptive Path, so we can just about see the glow from their aura.)
3 - Developers tell me things like "Rails is better for Web-based apps" and "You can collaborate easier in Rails" or "[something about dynamic libraries that is beyond me]."
A simple, plain English explanation would suffice. Or Mandarin Chinese, if you want, but I only understand household phrases like "kāi wánxiào."

Nicole
Written Sep. 29, 2006 / Report /
In my opinion this isn't an argument worth having. It comes down to what works best for your organization and the programming talent you have. An experienced, top-notch PHP can use a PHP framework and make it sing, but may produce a less than awesome RoR application. Likewise, a RoR developer probably wouldn't put out the best PHP application.
Also, when you're comparing PHP and Ruby on Rails, you're really comparing apples and oranges as PHP is a language and RoR is a framework. Perhaps you should be looking at Cake versus RoR.
HRJamie
Written Sep. 29, 2006 / Report /
OK, my fault. I did learn one more thing from our Rails developer:
So, for clarification, let me re-phrase the question:
For a consumer-oriented Web app, what are the pros/cons of PHP with a framework vs. Ruby on Rails? (Trying to make it more apples to apples - or ping guo to ping guo if you prefer the Chinese language.)
ylynfatt
Written Sep. 30, 2006 / Report /
PHP can handle search friendly URL's also. Most of the PHP frameworks out there have this feature. :)
AndrewIngram
Written Oct. 1, 2006 / Report /
Well, one argument in favour of PHP+Framework is that it's much easier to get it up and running with Apache.
I've not really done much with Rails, but i'd argue that if you already know PHP there's no reason to go with Ruby on Rails since excellent MVC frameworks exist for PHP (Code Igniter for example), likewise if you already know Python you should really go with Django.
It just comes down to language and function library preference really since MVC seems pretty much the same for all languages. I've not ever seen any compelling arguments in favor of Ruby on Rails other than the fact that it made MVC trendy and therefore learning it will make you more employable, it won't necessarily make you a better developer though.
Kyle
Written Oct. 1, 2006 / Report /
Why are Toyotas better than Hondas?
You can't generalize a technology and call it "better." The real answer is that RoR is better for programmers who like RoR, and PHP is better for programmers who like PHP.
Personally, have a million reasons -- but they're personal. I think that a programmer with the proper initiative can write more maintainable, stable, modular code in less time with Rails than they can with a comparable PHP framework. However, you must remember that that's with the proper initiative. It speaks nothing to the developers who have been developing in PHP for 5 years straight, and know nothing of Ruby. It speaks nothing for the developers who are looking for ease of deployment. It speaks nothing for the developers who are looking for ease of distribution.
I could come up with a million reasons that RoR is better than PHP, and a million reasons that PHP is better than RoR.
phantomdata
Written Oct. 1, 2006 / Report /
I believe that the primary benefit of Ruby on Rails when compared to PHP (with a framework) is Ruby. Truthfully, RoR with any other language wouldn't be as nice as it is.
Ruby comes stacked with all of the useful functions that a programmer needs - right out of the box, in an intelligent and well documented manner. Want to check if one string is contained in another? string1.include? string2. Not ( !(strpos($string1,$string2) === false)) (or however that goes) or anything else obfuscated. It's just /right there/.
philrenaud
Written Oct. 1, 2006 / Report /
ruby on rails will get you chicks.
php will not.
Rails like like an aphrodesiac to the stars. Forserious.
montoya
Written Oct. 1, 2006 / Report /
APPLES AND ORANGES!
I'm sure it has been said before, but look:
RUBY is better than PHP, because Ruby is a far more elegant programming language.
However, I do NOT think RoR is better than CakePHP or another PHP framework, because PHP is far better supported by servers. CakePHP is even compatible with PHP 4.
Done.
Scrivs
Written Oct. 1, 2006 / Report /
Has there ever been a well-done, side-by-side comparison of the two languages and two frameworks (RoR vs. CakePHP)?
HRJamie
Written Oct. 1, 2006 / Report /
Thanks for all responses. Some were over my head (more technical than I could understand), but helpful, nonetheless.
A couple people made a good point that "better" is relative [imho, 9rules is better than technorati :-)]. Phantomdata gave a good example of RoR code that's simpler to write. That seems to be the general theme I hear from RoR developers: 'easier' or 'more elegant' than PHP.
For non-coders like me, could anyone give some other examples where you would choose RoR over PHP when developing website functionality? (I'm trying to remove the judgement call of whether one is 'better' than another.)
Example: I know Corkd.com is an RoR app. Are there certain features that could only be done in RoR and not PHP? Or are some things just quicker to build in RoR than PHP (but could be done in either language)?
Kyle
Written Oct. 1, 2006 / Report /
Scrivs: Several times. As far as a pure framework comparison goes, you can't compare any PHP framework to Rails (and truthfully, Symphony would be a better canidate). Rails wins all the time: methods are more intuitive, there's more features, and more support.
The real battle between PHP and Ruby on Rails (and yes, you can compare them: PHP is most definitely a framework itself) lies in ease of deployment, ease of distribution, and CPU cycles.
HRJamie: Feature wise, there is absolutely nothing that RoR can do that PHP can't, and vice versa. RoR does make relational data much easier to deal with. Since the web is heavily heirarchical and relational, this is why it excells in the web space.
But again, when would you choose RoR? When your lead developer chooses it. Any other answer is garbage.
HRJamie
Written Oct. 1, 2006 / Report /
Ah, that helps. Many thanks.
"When your lead developer chooses it." <- That was one of the reasons for my original Q. When a web startup hires its first 'lead developer', should that person be more of a RoR coder or PHP? Sounds like the answer is "it depends." :)
AndrewIngram
Written Oct. 2, 2006 / Report /
Any coder worth the job title of "leader developer" would be able to become competent in a new programming language very quickly, to the point where it's irrelevant what languages they already know. Just hire a good coder who's aware of current web trends and processes and is willing to keep learning, and you're sorted
I'm not a great coder, but I can become reasonably adept at a new language in a day or two, i'd imagine the same is true of most programmers.
phantomdata
Written Oct. 2, 2006 / Report /
I think that there's one other factor to consider in RoR deployment; that is server support. While I'm gung-ho for RoR, I also host and run all of my own servers. While I know about Dreamhost... are there any other good RoR hosting companies out there?
Regarding the lead developer adapting to a new language; I'm not entirely sure that you want your lead developer of a web startup learning a new language and framework. I mean, PHP has a ton of frameworks available for MVC stuffs - and even here at 9rules you've seen two that have been subjectively compared. What new (to that language) developer's going to be able to make a quick judgment as to which ones are best for the job at hand?
I mean, hard economics... if you're picking the guy to be your first and best; you don't want to be making him change his language because of hosting. You want them doing what they love in the language that they love (within reason, I don't know that developing the next big web app in Lisp is quite applicable...).
I think that barring the hosting question (which I really don't know about, since I do all of that myself)... the question is more about the person applying. Are they passionate? Smart? Driven to completion? Do they test their code thoroughly? Those sorts of things. The language... as long as it's reasonably popular and supported... doesn't matter as much as the person using it.
blister
Written Oct. 4, 2006 / Report /
Wow. I can't believe that nobody has given this guy the correct information yet:
mod_perl + HTML::Mason is the only valid choice for successful web development.
Of course, that's just my opinion, and your mileage may very, so maybe you would be better off asking the developers you already have on your staff what they think... ;)
bouazza
Written Nov. 19, 2006 / Report /
In some ways , Ruby On Rails is better than PHP beceause i like the different way to program on ROR , but as i dont pay very much for very professional hosting , there ar'nt free or semi-pro host services providing Ruby On Rails !
A hosting like on Media Temple is strong , but it costs very much ( for me , money transfer from morocco ( where i live ) fees + Media Temple price ) .
paulbjensen
Written Nov. 19, 2006 / Report /
I'm learning both PHP and ROR, so I know a few bits but not the whole shebang.
PHP is pretty solid stuff and quite easy to get to grips with. ROR is a bit of a learning curve (for newbies like me) with things like MVC, but has a wonderful approach to creating web apps in a structured and concise manner. The other good thing about ROR is that it's got the Prototype Javascript library built-in, and AJAX is lovely stuff.
I'm particularly keen to learn ROR in order to build web apps as quickly as possible, so for me the choice between ROR and PHP is about speed, but if my priority was ease of understanding and use, then it would be PHP.
vikaskbh
Written Dec. 11, 2006 / Report /
My Personal openion is a person whoever firstly learn RUBY or .NET... won't ever able to learn advanced Java Scripting & even Advanced HTML coding...
From programmer point of view...
.NET & RUBY & Rails are languages for small kids... who Just interested in wrapper functions & don't interested to explorer, how actually things happening.
& those persons are limited to just .NET & Rails forever.... Can't ever dare to learn charming languages like perl,python,C++ & php.
blissdev
Written Dec. 11, 2006 / Report /
vikaskbh - i can't even respond to that. my eyes are twitching. must go to bed. i'll be content being a "small kid" and getting stuff done. on time. and i'm pretty sure that i can program in "Java Scripting" and "advanced html coding". And how the hell do you group ruby with .net and python with c++. seems kinda backwards. also... .net and rails are not languages... they are frameworks. so i guess they do "wrap" functionality, but with a logical purpose of speed, agility, and reuse. if you want to type things over and over and over again, be my guest.
oops, looks like i responded to that. night.
Ozone42
Written Dec. 11, 2006 / Report /
Neither is better than the other, they're just different methods to do the same thing.
Rails is a framework, so you have a lot of grunt work already done for you. It gives you an edge in development speed. I use my own MVC php framework for my development, so the point is moot for me.
JustinKistner
Written Dec. 11, 2006 / Report /
I believe Zeldman said it best:
As others have reiterated, PHP and RoR are just tools. Proper development would be to choose the right tool for the right job. It's true that RoR comes stacked with pre-made functions, which means developing certain web apps will be faster with RoR. However, because it does come with so many functions out of the box, it has a tendency to make developers lazy about considering the resource load it will take to run their app. There are more PHP developers in the world, which means it is easier to find additional PHP help. There are significantly more hosting companies that support PHP than RoR. Therefore as a general rule, if you're making an application to be distributed to the public, I'd use PHP. If you're going to make an enterprise level website that offers a service, you likely want to use RoR. However, there are exceptions to both of those rules. ;)
phantomdata
Written Dec. 11, 2006 / Report /
So, I'm quite certain that vikaskbh is a troll. I won't even respond to his broken tirade.
I do however sense a number of other posters thinking that having a useful language somehow causes a programmer to become lazy. I just don't buy it. Sure, there are things that can increase the load on the server un-necessarily - but programmers have been doing lazy things since there have been computers! The item at fault there is the programmer, not the language. I can see that if you don't have a good foundation in CSCI you won't really understand what's happening (knowing about reference passing, limiting memory consumption, understanding threading...) - but that's going to happen no matter the language (Recursion? What's that? I'll just copy and paste the function five times).
CSCI progresses. The languages that we use to express our most intimate instructions get higher and higher levels of abstraction as our problems themselves increase and multiply. Sure, there are times when low level languages are needed (say, popping into some assembly for an advanced search algorithm) but for the vast majority of the time, it's the programmer's time and comprehension level that's more important.
Do you want your programmer worrying about how best to sort that data (Do I use bubble sort or quick sort? Ack!) or do you just want him to type a single command that may be nanoseconds less efficient?
Oli
Written Dec. 28, 2006 / Report /
Lots of people have said correct things here. I've been involved in several "my language is bigger than yours" style arguments, and being an ASPNET dev (a proper server-control developer, not one of those Nancies dallying around with tags), I'm 100x smugger than the rest of them.
As many people have said here and elsewhere, you really need to go with your developers on this one. If you have a bunch of peeps with excellent PHP skills, you really don't want to force RoR on them because they will do a much better job in PHP.
Additionally, if you compare the runtime speed and how much memory an identical algorithm in Ruby vs PHP, you'll find Ruby is even slower than PHP. The "even" is there to suggest that PHP is slow and fat enough as it is. Many people pish this off as negatable against development costs but when you consider that Ruby is roughly 50x slower than ASPNET, and your server could take 1000 users with a RoR site, you could easily extrapolate that you could get 50,000 users on the same ASPNET site. There are extra overheads for Windows and IIS, so it doesn't exactly work like that, but it does work like that and I do speak from experience. Based on the last version comparison PHP is just 10x better. When you have to buy many, many servers to handle your Ruby site you might be able to escape with a very simple PHP setup.
Just to address the points as you threw them out:
>> 1 - Rails can handle search-friendly URLs.
Piffle. Any server side language can handle requests like that.
>> 2 - Rails is the hot Web 2.0 technology....
Tripe. Are you really going to make a business decision based on what's cool? Especially when the people using the technology never see the actual language.
>> 3 - Developers tell me things like "Rails is better for Web-based apps"
Utter nonsense. The problem you made there was you asked RoR developers looking for a job. If you asked the same question to a PHP developer, I'm sure it would be a direct rebuke.
The main problem here is you're trying to force Ruby [on Rails] to be the correct answer without any justification for why. Why do you want RoR to be the winner? You're not even going to use the language, you're going to force it down on people below you.
Just take a step back and talk to the developers.
posure
Written Jan. 5, 2007 / Report /
@vikaskbh
You are completely wrong. The truth is that people who start in scripting (JavaScript, Ruby, Perl, PHP, Python) or high level languages (Java, C#, VB.NET) will have an incredibly hard time learning low level languages such as C, C++, or Assembly. Ruby or .NET is less complex than JavaScript or "advanced HTML"? You must be joking.
Back on topic...
Having used both languages/frameworks, RoR and PHP/CakePHP are pretty much capable of the same things. If you're comparing Rails and Cake directly, it is a toss up to which language you are most productive in (personally I'd choose Rails in this case because the Ruby language is extremely sexy and fun to use - as long as you don't need to reference any documentation).
However, most of the time I choose PHP. This is primarily because it is more mature. The documentation is extremely well written and there are a large amount of well tested third party libraries available. Ruby is poorly documented, Rails is poorly documented, and the language itself hasn't been popular long enough to have many third party libraries which means you might have to develop some things from scratch in Ruby that might be standard in PHP.
When to use:
Ruby on Rails: Good for standalone web applications that have a WELL defined scope.
PHP: Catch-all, can do anything well.
ASP.NET: Good for portals, Windows-based intranets, and if you want to have access to commercial third party libraries. ASP.NET is technically a catch-all as well, I just don't like how its organized. Commercial libraries are the main reason for when I do use ASP.NET. Why? Because commercial libraries tend to have better documentation and have someone I can hold responsible if it messes up.
Java/JSP/etc: Good for enterprise systems (but should burn in hell).
Python/Django: Equal to Rails and Cake. Probably has better documentation and availability of third party libraries than RoR though (just a guess, this is the only one on the list I haven't used).
anadgouda
Written Jan. 5, 2007 / Report /
I think Ruby is better than PHP for those who like functional programming, it supports some of the elements. Comparing functional with imperative programming will also have its flavours of personal opinion and probably the work at hand. IMHO, there cannot be a generic Ruby better than PHP statement, or even vice versa.
igrigorik
Written Jan. 6, 2007 / Report /
The reason Ruby, or Rails for that matter, don't have as much documentation as PHP is exactly because they don't need it. Personally, when I write Ruby, I feel like I never leave the design stage of my application. I can express what I want to do, as it comes to my mind while I write my code.
I can't say I ever had the same feeling working with PHP. Don't get me wrong, I'm in no way putting down PHP, I simply prefer to write in Ruby because it's self-documenting, and a pleasure to work with.
PHP is not better than Rails, and Rails is not better than PHP. Functionally, they are all equivalent - in the end it comes down to personal preference. Take a look at my blog, I have a lot of Ruby in there - maybe you can get a feel for what Ruby has to offer.
posure
Written Jan. 8, 2007 / Report /
@igrigorik
I think you misunderstand what I mean by documentation. By proper documentation, I mean thorough reference material including full code examples as well as commentary on each method in context. See www.php.net or msdn.microsoft.com for proper examples. Maybe its just me, but I've found that the Ruby/Rails references are fairly useless for anything other than finding the syntax for a particular method.
As far as Ruby being "self-documenting;" no language, not even one as elegant as Ruby, is self-documenting. Maybe you're just writing extremely simple code, I don't know. I wrote some data management routines for a Ruby/Rails-based online multiplayer gaming system (unreleased, but it was a four player turn-based board game), and I sure as hell wouldn't remember how it worked if I didn't document my design. Not to mention it usually takes longer to read a block of code and analyze it rather than writing a short sentence to explain what is going on.
Ozone42
Written Jan. 8, 2007 / Report /
I installed rails on a production server for a client. I'm really not impressed. It may speed development and maintenance but the performance is very poor compared to php sites on this server.
igrigorik
Written Jan. 12, 2007 / Report /
@posure: It's true, Rails doesn't have nearly as many code samples, or full guides, but personally, I found the RDoc to be more than enough. It was non-trivial to start with Rails at first, but once I accustomed myself to Ruby everything just came together.
In terms of self-documenting code, you're right to an extent. I'm not advocating not keeping comments at all, but from experience, anytime I can't immediately see what's happening in a block of code.. it needs to be rewritten. This goes for anything, you really just have to be ruthless about your design. My Graphics World app is only 850 lines of code, and I wouldn't consider it trivial. Point being, I rewrote the design of each controller at least 3 times, and every time it would come out simpler and better. My experience with Rails.. If a controller action is larger than 20 lines, refactor it; if you have more than two nested ifs, refactor it.
You can look at some of my Ruby code on my blog and judge for yourself
@Ozone42: What software stack are you using for your Rails app? When properly configured, I find that Rails is no worse than PHP.
posure
Written Jan. 16, 2007 / Report /
850 lines is pretty impressive, I've had CSS files longer than that. ;-)
Thats one of the things I love about Ruby, short and sweet. I was able to reduce an AI routine that was 20-30 lines in any other language (and around 80 lines in BASIC on a TI-89) to about 4 lines in Ruby. Granted, the 4 lines of Ruby contained a very long chain of commands so it would probably still be equivalent to about 10-15 LOC.
letutor
Written Jan. 18, 2007 / Report /
I would like to know more about the business side and financial risks of developing with RoR.
I am creating a backend program to manage my business transactions. My developer wants to use RoR but I am hesitant for business reasons. I completely agree that technically RoR is a better language or framework to use.
However here are some of my business questions. If these types of questions can't be answered so that decision makers feel confident then I doubt that RoR will gain the traction it needs to become mainstream.
*keep in mind I don't want any technical arguments about the languages ability. I am making financial decisions. Php could do what I want it to it.
1. If I no longer work with my current programmer how difficult will it be for me to find a qualified programmer and what could be the expected hourly rate.
Currently Php programmers are a dime a dozen and you can find a quality coder for $20 per hr.
2. If RoR doesn't gain mainstream popularity will hosting companies likely drop RoR from their services? My current host offers RoR servers but I am afraid that it could go away.
3. If I started with Php to be conservative and then wanted to convert to RoR how easy or time consuming would this be?
If you want to know more about my business to offer a better answer check us out at http://www.letutor.com or http://www.letutor.com/blog
posure
Written Jan. 19, 2007 / Report /
@letutor
Generally, if you are contracting a web application that will need future maintenance, do NOT use Ruby on Rails. It isn't as cheap to maintain due to the lack of developers out there. You would be better off with PHP or ASP.NET at the present time.
1. There isn't a huge number Rails developers right now, however, it has been picking up at a pretty fast pace and this could change. As far as hourly rate, I have no idea, the language doesn't really factor into my fees personally - but I wouldn't be surprised to see Rails developers asking for more given the lack of developers out there.
2. Based on the shared webhosts I have used, the Rails performance is less than stellar due to limited memory. For any serious production deployment of Rails, it would be better to have a dedicated server where you can allocate more resources to Ruby/Rails. This is probably another reason to use PHP instead (unless its with a Rails-only host or something). Rails has enough steam that I don't anticipate it going away, you could always set up your own dedicated server with whatever you want.
3. There isn't really a good enough reason to switch once you start with PHP. If you want a Rails-like framework, just use CakePHP instead of naked PHP. The features are pretty much the same, the only difference is the language driving it.
Bottom line, PHP will be cheaper to maintain due to the much larger availability of PHP developers.
igrigorik
Written Jan. 19, 2007 / Report /
I'll play devil’s advocate:
1. True, based on the sheer numbers it may be harder to find a RoR developer. Having said that, the framework has a big and a growing following. I doubt this trend will decline anytime soon. It should become progressively easier to find a RoR developer.
2. Sure, Rails support is not as ubiquitous. But again, frameworks don't just 'die'. The support is there, Ruby is gaining in popularity, everything is looking positive.
3. There is no point in starting with PHP and then converting to RoR. If you already developed your application in PHP then you won't get any tangible benefits from the conversion - they both do the same thing.
Here's the catch, and real selling point of Rails.. It takes less time to develop in Rails than in PHP. If you spent 2 months coding your application in PHP, you already overpaid for development - no point in switching to Rails. The converse is better: you can develop a Rails app in a month and save on the development costs. Same goes for maintenance. If all of the sudden you decide to add a new feature, the cost of the developer may be higher, but he will get it done faster. It's a tradeoff.
So as such, I'm fairly certain that I can challenge posure's argument. PHP may be cheaper by the hour, but it will usually take more hours. And last but not least, this is also highly contingent on the developer himself. But that goes without saying.
posure
Written Jan. 19, 2007 / Report /
@igrigorik
If you're using CakePHP, the development time would be similar to that of Rails or Django. Rails/Django development is still slightly faster since Ruby/Python have better data manipulation abilities, however, that difference is probably a negligible trade-off given that this would be for a contract job.
VisVires
Written May. 2, 2008 / Report /
I know php very well and i find it a very cool programming language for web applications. But you people say ruby is better,so i think i am gonna look what does ruby represent and why people like it so much. It would be very nice if somebody gave me some links to ruby on rails tutorials.
_________________
http://websitetools.110mb.com