Ruby on Rails vs PHP – The good, the bad

Note – this article was written in 2012. I’ve added an addendum to update the article with latest thoughts on May 30th, 2014 at the bottom.

I’ve been developing with PHP since version 2 (a very long time ago). I had been wanting to get into Ruby on Rails and had played with it since version 1 but never had the chance to really use it in production seriously until this past year with Ballistiq. Since then, I’m now coding 80/20 Ruby on Rails and PHP, so I’ll give my thoughts on the two. At the time of writing, the versions I’ll be talking about are PHP 5.3/PHP 5.4 and Ruby on Rails 3.2 (running on Ruby 1.9.3). The context of this post is comparing the two specifically for web development.

Aren’t you comparing apples to oranges?

Yes.

Rails is a framework for Ruby. PHP is a language and has many frameworks. What I’m mostly comparing is my experiences working with both ecosystems: PHP + framework (there are many) vs Ruby + Rails (the predominant framework). While some may get hung up over trying to compare the two and may balk at the title of the article, this is a legitimate question that many developers ask. Many developers want to know what are the benefits/shortcomings of both ecosystems and genuinely just want a clear answer. From the popularity of the article via Google, it’s something that tens of thousands of people actually are asking.

Isn’t it just a preference?

Yes and no. Both the PHP and Ruby ecosystem are very powerful. In many cases, yes you can just boil it down to a preference. However, there are many strengths for both and it’s useful to be able to compare them in a level-headed fashion. I’m not religiously attached to one or another. I’ve used both. My company works with both. Both are here to stay and play important roles in the global web development industry.

PHP – The Good

Simplicity and Learning Curve

What I absolutely love about PHP is its simplicity and relatively shallow learning curve. When you first get into PHP, all you need is a single HTML web page. Change the extension to .php. Throw in some <?php //code here ?> inline PHP, run it on a PHP web server and off you go. It’s really dead simple for someone totally fresh to get something usable done and deployed within a few minutes. This has been one of the strengths of PHP and why it’s so darn popular — designers and non-coders can be productive right away.

This simplicity, however, comes at a cost. It is a double edged sword as it leads to a lot of sloppy, unmaintainable code. This leads people to use frameworks that force a particular coding standard. The benefit of PHP’s simplicity and shallow learning curve is a really big thing going for it and this has business benefits too: it’s easier to find people who know PHP. If you look around, Ruby on Rails developers are more expensive and harder to find. The good developers who really know Ruby and Rails (the L33T) tend to be more hardcore devs.

The documentation for PHP is also fantastic. I find the docs for PHP far more useful than the ones for Ruby and the Rails Guides. The user comments really help and there is a lot of example code that shows you how to solve common problems.

It’s Made For The Web

One big thing about PHP is that it really is focused entirely for the web. It’s not a general purpose programming language like Ruby (or Python/Java/C/Perl/etc.). Many of its inbuilt functions are specific to solving web problems and this makes it a very straightforward language to program for the web. E.g. if you want to send a header to the browser, just use the header() function. An MD5 or SHA1 hash is simply md5() and sha1(). It’s not as straightforward to do this with Ruby/Rails as you have to load in libraries and use namespaces/modules to get to the same functions.

Lot’s of Resources

PHP has a ton of resources, frameworks, applications and libraries available for it. From CMS’ like WordPress and Drupal to frameworks like Symfony and libraries like Doctrine, PHP really has a lot of good resources available. When it comes to deploying a simple CMS, for example, I almost always default to just using WordPress instead of building a Rails app for it. I just feel that it’s a much simpler solution.

Dead Simple to Deploy

Deploying PHP is dead simple. At its simplest, you just FTP the files to a web server (which we at Ballistiq never do – we deploy using Git). Thing is, with PHP you don’t have to know about or care necessarily about the web stack. Many hosting services just use a LAMP environment (Linux, Apache, MySQL, PHP), so as long as your files are in place they just run and that’s that. Even using a framework like CodeIgniter is relatively simple as you don’t ever need to use the command line — you just copy the entire framework directory onto the server and run. That’s it.

PHP – The Bad

Its Evolution Led to a Lot of Bad Code

This is not a direct feature flaw of PHP, but is the result of years and years of building on top of a simple scripting language that was specific to solving simple web problems. PHP was not always Object Oriented. Even when it did support OOP, for years it was not really OOP (missing important features like static methods), so programmers got around the problems through all kinds of shenanigans like using global variables or setting a local variable using a global reference pointer.

E.g. Typical pre-PHP5 code

//Ex1 Using global variable to get reference to database handler
function getPost($post_id) {
  global $DB;  //Stick global variables everywhere in code
}

//Ex2 Using reference - pattern used in CodeIgniter
class Post {
  var $singleton;

  function Post(){
    //Returns a reference to a singleton object
    $this->singleton =& get_instance(); 
  }
}

These are just a couple of examples, but there are more which I won’t go into here. It’s unfortunate but is just one of the side effects of working with a language that has evolved rapidly.

One thing that drives us crazy at Ballistiq is going into projects where we have to upgrade or maintain applications written with old PHP. This is the case with one of our largest projects where we’re trying to upgrade a large app written in PHP4 code and it is horrific. A lot of sloppy code there that we have to work with.

Better Coding Standards Lead To Really Purist Code

As mentioned above, sloppy code is not an inherent feature flaw of PHP. It’s just how people have used the language. As PHP has gotten more popular, it’s gotten a lot of influence from enterprise developers who take a really purist approach to programming. When you go to conferences and listen to these PHP experts talking about best practices, PHP no longer becomes fun to program. You’re almost looking at a Java program. Classes explicitly declare namespaces, importing namespaces, explicit getter and setter methods, explicit declaration of public/private methods, etc. The code becomes extremely verbose. Now If you want to see a framework that takes a more purist approach to things, check out Symfony. It’s a great PHP framework that’s ready for enterprise level usage but from a development point of view, I find it tedious.

Ruby on Rails – The Good

Mature Framework

The more I develop on Rails, the more I really appreciate and love it. I’ve found that it enables us to create higher quality products for clients much faster, that are more maintainable. It’s a mature and stable framework that many large companies are comfortable with introducing into their environments. Compare this with the PHP ecosystem that has many frameworks — there’s a risk of selecting a framework and finding that it’s just not that well supported several years from now (we made this mistake).

Speed and Development Joy

I absolutely love working with Rails because as a development platform, it is extremely automated. So many menial tasks have been automated so that you just focus entirely on solving the business problem instead of hacking your way around a framework. Some things really going for Rails in this regard are:

  • Generators/Scaffolding – Provide a very good starting point for developing around. Some PHP frameworks now provide scaffolding features.
  • Gems/Plugins – the Rails community provides a wealth of plugins as Ruby Gems that you simply add to your project Gemfile and install. This significantly accelerates development and maintenance time as you’re not trying to integrate disparate libraries, it’s already done for you.
  • Active Record ORM – Of all the ORM’s I have used (for PHP I’ve used DataMapper DMZ, Fuel/Kohana, Doctrine), ActiveRecord in Ruby on Rails is simply the best. It actually works and is remarkably straightforward to use.
  • Integrated testing tools – I love it that out of the gate, Rails has a testing framework that can be used. In PHP, many frameworks have only recently been trying to integrate PHPUnit, to varying degrees of success.

As a programming language, Ruby is really quite an amazing language. Unlike PHP, it really is Object Oriented from the ground up. Its code is very concise and powerful. Gems (extensions) enable you to bolt on needed functionality. After coding in Ruby, I find coding in PHP (or anything else really) rather tedious.

Ruby on Rails – The Bad

Steep Learning Curve

My main beef with Ruby on Rails is that it actually has a steep learning curve. Do not believe the hype that says that it is really easy. They will show you podcasts where you build a simple blog application using scaffolding and voila! Instant website. Nothing could be further from the truth. Rails is seen to be easy because they have automated many things in the framework — this does not make it easy to understand.

Developing a Rails app and deploying it actually requires you to know the full stack. With PHP, you can just cobble together some inline PHP code, FTP it to a server and off you go. In Rails, you really need to know what you are doing from the web server (Apache or NginX), setting up Phusion Passenger and database engine. Then you have to deal with the asset pipeline process to prepare your app to run in Production mode. It’s not as simple as running it in production mode — you have to precompile your assets and make sure files are actually there. If they are not, Rails will simply blow up and you have to find out why by accessing the Rails logs.

Compared to PHP, Rails is also unfriendly when it comes to errors. With PHP, it will spit out errors at you in development and the error messages actually make sense. Typically a page will render but the part with the error will show you which line the error occurred and the message is useful. In Rails, typically the whole app blows up.

One last thing to throw in is that good Ruby on Rails developers tend to be polyglots. They are able to pick up and learn many languages. While beginners are battling to just learn Ruby, Rails people are using CoffeeScript instead of Javascript, SCSS (or LESS), and Slim or HAML. For a newcomer to Rails, part of the steep curve is not just learning Ruby and the Rails framework, but all these other languages as well!

Ruby is not an easy language

I’m sorry to offend some people here, but Ruby is simply not as straightforward as PHP to learn. It is by all intents an extremely powerful language. I choose to use Ruby simply because as a developer I feel it is a much better language than PHP. But from a learning perspective, it is not.

Ruby has many features that are simply not straightforward for a beginner programmer to understand. One such concept are blocks, procs and lambdas, which Rails uses heavily. The classic Ruby on Rails example I will use is for creating a form:

<%= form_for @user do |f| %>
  <%= f.label :first_name %>
  <%= f.text_field :first_name %>
<% end %>

If you’re new to Ruby, you can be forgiven for saying, “Wait a minute….what’s f?” Yes sir. Welcome to blocks.

Here’s a bit of an extreme example:

(0...8).map{65.+(rand(25)).chr}.join

Even as an experienced programmer, I went crosseyed when seeing the above line of code. It’s very simple actually – generate an 8 character random string.

Another area is meta programming. Here’s an example:

class Client < ActiveRecord::Base
  has_one :address
  has_many :orders
  has_and_belongs_to_many :roles
end

I’ve taught Ruby on Rails to experienced developers and this always trips them up. What exactly is has_one, has_many and has_and_belongs_to_many? It looks like it’s some kind of reserved keyword or declaration as these are not encapsulated in a method. However, in Ruby, ALL code is executed. Every line of code is executed, so has_one, has_many and has_and_belongs_to_many are just methods that execute when the class is declared.

Finally another thing that makes Ruby challenging for beginners is its loose syntax. Let’s look again at the above code. It’s not obvious (to a beginner) that has_one :address is invoking a method because the brackets are missing from the method invocation. In PHP, the syntax is stricter and this makes it simpler for beginners to know what’s what.

As a language, especially if you’re coming in from others such as C/Java/PHP, Ruby is challenging and it will bend your mind. Once you’re up and running though, it’s fantastic and many who have taken the leap really enjoy coding with it.

Conclusion

So from all of that, what do I conclude?

PHP is a friendlier entry point into web development than Ruby/Rails. It’s easier, there are more resources available and you can get results fast.

Despite this, I personally enjoy working with Ruby and Rails more than PHP. For many of the reasons I’ve described in this article, I just feel that the Ruby ecosystem offers a superior toolset for developing applications. I respect that the die-hard PHP fans won’t feel the same way – that’s cool. My opinion has formed from working with both languages and ecosystems thoroughly in production. Since moving to Rails, I’ve never really felt much of an urge to move back to developing with PHP and so all my new projects tend to be Ruby/Rails.

At Ballistiq, we develop in both.

If a client project already has existing PHP code and we’re developing for that, needing to integrated at the software level, we stay in PHP.

If a client needs a brand new application, or we are building our own app use Rails.

Addendum – 30 May 2014

Wow it’s been a while since I wrote this and it continues to be a very highly ranked article on Google, which attracts a lot of traffic. Because technology advances at such a breakneck pace, I wanted to update this article with some new thoughts.

PHP has come a long way since I wrote this article

When I wrote this article, PHP was in a bit of a transitory phase as many folks were still using PHP 4 and trying to migrate to 5. Symfony 2 had not yet been released, and Laravel just was not a big thing. As of right now, PHP is having a bit of a renaissance. Here are some great technologies that really make PHP shine:

  • Laravel – As a framework, Laravel looks really excellent and many PHP folks have chosen it as their framework of choice. I can’t speak for it because I haven’t used it in production. But it does look good.
  • Composer – Composer is to PHP what RubyGems + Bundler is to Ruby. It does package management that doesn’t suck. For years the PHP community had to deal with Pear, which really didn’t gain much traction.
  • PHP web server – For the longest time, developing with PHP on your computer meant that you had to rely on an external web server like Apache. Many devs ended up installing MAMP. As of PHP 5.4, PHP now comes with its own command line web server, and it’s actually remarkably easy to fire up. Now, not everything works with the command line web server (I had trouble getting WordPress to boot up with it), but if you’re developing with a framework that supports this, it’s a much nicer and saner way of developing.
  • Codeception – One of our team members at Ballistiq gave a really nice talk about a testing framework called Codeception, and I have to say it actually looks decent, supporting things like Selenium and BDD style tests.
  • HHVM – Opensource project led by Facebook, this takes PHP and compiles it to bytecode that in turn gets translated into x64 machine code and runs really fast. This is a very interesting project that makes PHP highly performant and scalable.

So PHP isn’t going away anytime soon. Many people use it and put it to good use.

However, I (and many web engineers) have moved on. As engineers, we’ll hack in anything that we need to get the job done, however, by choice, I won’t start a new project in PHP. Why? I feel that there are more interesting solutions out there that are worth looking at.

Why I still love Rails as a framework and Ruby as a language

As I mentioned back in 2012, I really enjoyed working with Ruby and Rails. Despite it’s steep learning curve, after a while I hit a groove and now the applications that we are delivering are so good that I can’t imagine going back. Here’s some of the things going for Ruby/Rails that I feel really make it such a strong choice:

  1. Gems – When I started coding in Ruby, Gems confused me more than they helped because there was too much ‘magic’. Once I learned that you could (and should) just read the source code for gems, everything made so much more sense. Due to the pluggable nature of gems and the community’s standards, gems can give your application a tremendous amount of functionality very quickly. Some gems that I cannot live without: Devise (authentication – handles user logins, social sign on, forget password workflows and so much more), Paperclip (file uploads – even handles uploading to S3, image cropping/resampling), Simple Form makes forms incredibly simple to standardize and render on websites.

  2. Mountable Engines – We did a mammoth project for a Fortune 500 company where after building the initial application, it was so successful that other departments wanted the same application, but with slightly different functionality and different UI. Rather than copy/pasting the application and having to support several codebases, we were able to extract most of the core functionality into a Rails mountable engine, and literally have one codebase but several websites. The client was absolutely thrilled with this and it was a huge win for us.

  3. Scaling – Rails has a stigma of being unable to scale and they are referring to Twitter dumping Rails. We have not found any scaling issues with Rails and we have applications that run with millions of pageviews and hundreds of thousands of users each month. The fact is, majority of you will never have the scaling problems that Twitter had. And…in fact, we found it easier to scale with Rails than with PHP. How? First of all, Rails supports caching out of the box. You’re able to do view fragment caching within your application code and use Redis as a cache store. That is a far simpler solution than trying to use Varnish which caches everything that goes through it and leaving logged-in users without caching. Using built-in Rails caching enabled us to scale easily. Secondly, Rails + Capistrano + Chef makes it very simple to scale to multiple server environments very quickly. Our typical Amazon AWS infrastructure includes Elastic Load Balancer, several application server instances + a redis/search server, backed by an RDS database instance. We set up server provisioning with Chef, enabling us to provision a new ready-to-run instance in minutes. Simultaneous deployment complete with data migrations can be done with Capistrano from the command line. Literally, I type in cap production deploy:migrations and everything is magically deployed to all our application servers. Users don’t see any downtime as we have Phusion Passenger Enterprise and rolling restarts.

  4. Background jobs – PHP was designed as a hypertext pre-processor which means that it executes only when there is a web request. Compared with Ruby which runs a process. In Rails, you can easily set up background jobs using Sidekiq or Resque. This also adds to Rails’ ability to scale easily. In our applications, we move a lot of stuff that can slow down requests like emailing users into background jobs. Now, PHP can do background jobs using Gearman but that’s not standardized – you have to install the PECL extension. In Ruby/Rails, background jobs are a non-issue. You just do it.

  5. Rails is BORING – Rails is now at version 4.x. It’s a mature framework. It’s boring now. The cool kids are touting NodeJS these days. Rails is boring because it’s robust and stable. We’ve developed apps in Rails now for some of the world’s largest companies and people in their IT departments don’t bat an eyelid. It’s known that it’s a good choice to build your (robust, enterprise-ready, scalable, performant) application on.

Other technologies that I think are shaping the web

  1. AngularJS – We introduced AngularJS into our client projects earlier this year for two Fortune 500 companies and it was a huge win. AngularJS enables you to build single-page applications that run in Javascript. Most of your front-end logic goes into AngularJS, and your backend simply because an API that serves JSON. Doing this, we were able to build highly performant applications. The user experience is very good with this approach because pages load extremely quickly as the browser does not have to do a full roundtrip request.

  2. NodeJS – I started developing in NodeJS a few months ago and it blew my mind. What NodeJS is very good for is building networked applications. E.g. if you’re building a real-time chat application, you can use NodeJS for that. Due to the maturity of Rails, I don’t think we’re moving off that anytime soon for building large applications, but to add real-time components, I would use NodeJS + SocketIO.

So what should you do?

Web development is becoming incredibly complex. The days of a single developer being able to ship a full application from start to finish are becoming more difficult. Even front-end can no longer be handled by a single hybrid designer/developer who can hack CSS + HTML markup.

If you are just starting out, I still recommend that you start with PHP. You will get results much faster, and this will fuel your growth and knowledge. Jumping into Ruby/Rails as your first language might leave you really frustrated trying to get results – remember, with Rails, you have to know the full stack so it’s not just the language and framework you’re challenged with.

Once you’re comfortable with building bespoke applications in PHP, you can then whet your appetite and start using other technologies like Ruby/Rails and even NodeJS/Express, and you’ll appreciate what these technologies offer. Many of the concepts you will learn from PHP in frameworks like Symfony & Laravel will carry over to other languages and frameworks.

Another reason why I recommend PHP as a great starting point is that it’s very useful to know so that you can hack on things like WordPress themes and plugins. WordPress is so widely used today in business (especially marketing departments) and it’s great to have software polyglots who can work with many different tools and platforms.

The thing that you have to realize is that the Web is not about what language you choose to develop with — it’s about the standards and what it takes to get information in and out of the web browser. It doesn’t matter what is on the server, as long as it spits out HTML and the right JSON data – you can use C for all anyone cares. That’s why there are so many web technologies from PHP to Ruby to Python to .net to Java and gosh Perl is still used (I met a guy that wrote a Shopify App entirely in Perl!).

So there you go. Keep on hacking! 🙂

Leo


Photo by Filippo Venturi

  • Richie

    As a total newcomer this post is extremely helpful. I’ve been testing out python, Ruby on rails, and PHP on codecademy and cloud9 IDE. Ambitiously I thought RoR would be the best choice but learning the full stack is a challenge I just don’t have time for if I’m focused on launching anything soon. PHP just works and that’s one less thing for me to worry about. Thanks for saving me some time and frustration.

    • Michael Muryn

      As a note: I’m doing mostly PHP, and I have not done any Ruby/RoR works. Still, I have to say that sometime taking an upfront time to learn something (be it RoR or a PHP framework, etc.), and then going faster… make you go faster in the end. And we have to ask ourselves if we can afford that lost.

      “Easy training, hard battle. Hard training, easy battle!”

      An academic example I was using is when studying for a Math exam. If you have 5 chapters to study, and you have only some hours left. If time scare you and you skip too fast the first chapters even if you don’t understand well, the last chapters will usually be very hard to figure out. However, if you take the time to study the base chapters well, the following chapters will just make sense as they usually just extend the base more deeply.

      Sometime in work environment we tend to value the “safe” route because we are scare of something, but often it is not the right decision.

      All that said. PHP is not necessary a bad decision, you can achieve a lot with just simple code too.

  • Alejandro

    Leo, try Laravel 4!!

    • leonardteo

      ANOTHER PHP framework!? lol. 🙂

      • Thomas Clarkson

        Seriously try Laravel 4

  • rubyasaman

    lol I picked ruby as my first script language because my friend told me ruby is easy… screw them lol

  • Scott

    You can do anything in PHP that you can in Rails and visa versa. That’s enough for me to stick with PHP.

    As far as Rails being faster to deploy, I really doubt it. There is not much time that can be saved in PHP vs. another language with the existing frameworks I already use (unless of course, we build AI to start programming code).

  • Danmar Herholdt

    Nice article. I totally agree because I’ve had the same experience coming from a PHP background over to RoR.
    I’m just glad I’m not the only one that thinks learning Rails is difficult. I’m still trying to get my head around Coffeescript.

    I would like to offer some advice to readers, a really good way to learn Ruby and Rails is by doing the FREE SaaS course from Edx (https://www.edx.org/course/uc-berkeley/cs-169-1x/software-service/993). Not only will you be learning solid Ruby on Rails, but you will learn good engineering aspects and end up with a certificate from Berkeley University as well!

    Other than that, I can recommend the Ruby on Rails Tutorial 2ed by Michael Hartl. and Head First Rails (O’ Reilly).
    Remember, the more you give RoR a chance, the more you’ll love it.

    Good Luck!

  • BlessanBabuMathew

    Great write up. Im more of a javascript guy who occasionally uses php for the server side. Since node came, started to use javasript on the server side too. A lot of the cool tools that I use like Jekyll, Sass and compass are written in Ruby, so I always got tempted to learn ruby. I have observed a lot of my colleagues moving to Ruby or Python because they feel that being a php programmer just doesn’t get the same respect.

  • William Morris

    Great, balanced article Leo, thank you for not hyping one or the other and remaining objective about your experience. Deployment complexity of RoR concerns me, while I like the other aspects.

  • webcoderph

    Nice article. Im both PHP and Ruby on Rails programmer. I choose Rails because unlike PHP there’s too many to study depending on your needs. A lot of framework and cms. While Ruby, rails is all you need. you can do scale apps.

  • Really helpful article, Leo. I’ve been dipping my toes into web development for the last six months and have been working mainly with PHP, however Ruby on Rails is next on my list of languages. As an experienced web developer, would you suggest I continue with PHP and move on to Rails after I get some experience? Or jump right into Rails?

    • leonardteo

      Hi Michael. I think it is valuable to know both. Definitely in the current climate a knowledge of Rails will get you a job very quickly as there is more demand and less competition.

      If you are completely new to web development, I think PHP is a better starting point because you will get results faster, which will spur you on to continue in web development. I can’t stress enough how small successes build on each other. You can build a good, custom MVC application quickly using something like CakePHP or CodeIgniter.

      When you do move to Rails, I’d advise not to learn Rails first. Learn Ruby first and try using a framework like Sinatra to start with. My reasoning is that Rails has too much “automagic” which makes it very difficult to understand what is happening under the hood. If you don’t understand what Rails is doing under the hood, and you don’t know how to look in Rails source code and figure it out, debugging your applications can be very long and frustrating, especially for a beginner.

      Good luck mate!

      Leo

      • Thanks for the helpful response Leo! I definitely agree that learning the Ruby is super important before jumping into Rails. There’s definitely a lot to learn for me still but I’m super excited and motivated by each little success.
        Cheers!

        Michael

        • Mark Evans

          Couldn’t agree more. As a newer Ruby and RoR dev, it was instrumental that I learned Ruby first. While RoR is Ruby at its core, it handles a lot of the rudimentary tasks for you… hence, Rails “Magic”. If you don’t have a decent grasp on how to use Ruby without a web framework, what’s going on under the hood will absolutely frustrate you, especially when it comes to debugging or even understanding what the right tool/method is for the job.

          Great article, Leo! I, like most others, appreciate the fair and balanced representation of both languages and their respective frameworks.

  • Nicholas

    or chars = (‘a’..’z’).to_a; Array.new(8) { chars.sample }.join

    • How about this (‘a’..’z’).to_a.sample(8).join

      Great article @leonardteo:disqus

      • Rok Kralj

        No, because your solution doesn’t allow duplicate characters.

  • marcio arantes

    fantastic article I agree 100% with everything you said expect one thing “In Rails, typically the whole app blows up.” as I learned with objective-c this is a plus in my book especially if you don’t care about testing or TDD/BDD

  • wahyu

    how about server resources usage ? what’s is better ? PHP or Rails ? , need your suggestion . thank 🙂

  • Sachin Kulkarni

    @leonardteo:disqus – Which was the first language you learnt ?

    • leonardteo

      First language I ever learned was Turbo Pascal. 🙂 Then Java. First web programming language I learned was PHP.

  • Aardee

    Very informative. I’m new to programming and am looking at both PHP and Ruby as server-side languages (I’ll decide which one to go with once I’m in to it a bit more). I agree that PHP is easier to pick up ‘off the bat’ but it is very hard to find good quality tutorials or guidance out there. It’s ridiculous really seeing as it’s been around for so long. On the other hand Ruby does have a steep learning curve (though learning PHP in tandem seems to have helped me understand it) but the resources for learning that are out there are both easier to find and a whole heap better. Code school, for example (check it out if you’re new to development) is a fantastic resource… but doesn’t even touch PHP. I see Ruby as the SS language of the future.

  • Beyowi

    I am working on Ruby on rails. Using Ruby on rails to build rock solid code thus quality websites that will be easy to maintain afterwards. Ruby on Rails is also well known for its coding convention, Agile practices and security strength. But it is valuable to know both!

  • Nick

    Nice article. I’ve been getting into web dev with Rails over the past few months and it’s nice to see that I’m not alone in my belief that it simply isn’t very intuitive. The comparison is indeed like apples and oranges, but it is useful when considering which area to focus on studying. I’m currently picking up industry experience with Rails, but am hesitant to commit to going the full mile in that area because the curve is so steep, and I don’t know if I want to be a Rails dev.

  • Martin

    Good article. I feel exactly the same way. After >10 years php and Java I learned to like ruby. And the peace of mind that rails gives me in a stressful project. Blindly knowing where to put new code even after 12 hours of coding at 4 in the morning. But I really hate the complexity you mentioned concerning the infrastructure setup. Some people enjoy that – I don’t. Live is too short for such stupid tasks. I always wonder why can’t the Ruby/Rails folks manage to create a setup routine that’s as as easy as php? Why do I have to fight with Ruby version / gem version / mac OSX version inconsistencies for 2 days before rails server will run the first time? Grmpffff….

    • Halil Özgür

      Actually, you don’t have to “fight with” versions.

      – Ruby versions: Generally managed by rbenv/rvm et al. (rbenv is officially recommended by Rails – http://rubyonrails.org/download). If your native Ruby satisfies the Ruby version required by the project at hand (e.g. 1.9.3+ for Rails 4, 1.8.7+ for Rails 3.2) then you are good and you don’t need those tools. But if you are doing client work, or even experiments (e.g. your main project is Rails 3, you are experimenting on/planning on switching to Rails 4) you’ll need multiple Ruby versions running simultaneously in the same machine. You can use Vagrant et al. but that can’t beat having it in your base OS.

      Rbenv/rvm/etc makes this possible only with a few lines of commands. You can say that one can just use the latest possible Ruby, but it doesn’t always work like that (compatibility problems etc). Now try that with PHP. There are PHP version switching tools but they were nowhere near mature/full-fledged/easy-to-use as rbenv/rvm last time I checked.

      – Gem versions: Seriously? Show me a single language/framework with a package/dependency manager that doesn’t involve version numbers (e.g. PHP’s composer, Python’s PIP, Closure’s Leiningen, Java’s Maven)? Ever heard of DLL Hell?

      – Mac OSX: I’m an Ubuntu user but I’d be surprised if you can’t get anything related to Ruby/Rails working in MacOSX, seeing that most Rails developers are using Macs.

      – You need to to install rbnev/rvm on a machine only once. After that, you can install any version of Rubies and Gems in a matter of minutes. And with Heroku, you can see your thing in interwebs in seconds. And you have proven deployment tools like Capistrano which works for any empty Linux box. Yeah, PHP shared hosting is really ubiquitous (in most of which you still can’t reliably/securely run modern PHP frameworks), but here the scopes are really different.

      …from a long time PHP user who is busy switching to Laravel 4 and Rails 4 at the same time in production projects for the last 1-2 months.

      • James

        I’m just finishing up a big L4 project and about to get started with ROR myself.

  • webcoderph

    Nice article. I agree. It’s hard to study rails but its worth to try. I come from PHP environment, what i hate about PHP is there are a lot of framework to study. Working with different client’s with different framework….. just give me headache’s just by thinking of all codes that i study.

  • theareba

    I couldn’t agree more. Looking at the comments below, some people seem not to want to admit to the truth. I’ve been developing using RoR for a year and a half now. I started with python-django and almost went back to it after switching to RoR because yes, learning RoR is not easy. But here’s the deal, once you’ve grasped it, bam! It’s MVC(model-view-conntroller) nature makes it amazing and as Lenard said, speedy to use due to the automations. Personally, I haven’t tried PHP but I understand it’s concept. I respect diversity and would encourage anyone out there who’s comfortable with PHP to stick to it. On the other hand, RoR’s superiority cannot go unmentioned. Nice article.

  • Seeing this, maybe the Ruby version is simpler! 😀

  • Juan David Pastás Rivera

    Hi Leo, has your agency worked with any other PHP framework? Why did you select that one?

    Really good post, thank you.

  • Leonardo Lobato

    Great Article!! I’m learning rails, coming from PHP background (with laravel – based on symphony) and I’ve always heard that rails was easy, well!! after your article I have my doubts. but I believe it worth!!

  • Well, I don’t think Laravel wasn’t released when this article is written

  • Suraj

    Good Article!!! you forgot one thing programmers are often crazy. When you say something is hard to achieve they will definitely try that… its just ruby…. IF in php ==== IF in ruby and ‘=’ in ruby would not multiply values;

  • Paul Redmond

    Great post! Just what I was looking for as a PHP dev looking at Ruby. I’ve been learning Rails and struggling with “what’s all the buzz, not seeing it yet”, but I think ill press on.

  • Anthony Candaele

    Hey Leonardo, this is a very good write up. Although I’m not confident with PHP, I’m kind of in a similar situation. I used to make websites in the CMS framework Umbraco, an open source CMS based on .NET (yes they exist). For simple websites in need of CMS functionality, this is an excellent choice. As Umbraco as a development framework let’s the developer build fully customized website with excellent CMS capacities. To the end user (editor), the CMS backoffice is very easy to grasp and use.

    But also I found myself, for more complex web applications, hack my way around the framework to implement application scenario’s. Enter Ruby on Rails. It’s like you say, RoR has a more steep learning curve, especially for a guy like me that used to code mostly in the Microsoft Stack. I had to make myself comfortable with the basics of the Unix command shell, and of course learn the Ruby programming language.

    But doing this, I really improved as a developer. I learned to develop applications in a TDD way, wich leads to more robust and flexible ( extensible ) code.

    To free myself from heavy convoluted IDE’s, I even learn to use Vim as an editor.

    Something under stressed in Ruby on Rails is also it’s Agile development process. As I already mentioned, TDD is a higly regarded practice in the Ruby community and some of it’s testing tools like Rspec and Capybara are really superb. It learned me regarding the software development process to see it more as a craft, that makes you proud of your code, than hacking your code in an Ikea equivalent fashion.

    greetings,

    Anthony

  • Jordan

    mt_rand(10000000, 99999999)

    sheesh, I hate correcting things that shouldn’t be said in the first place/

    • omnitool

      @disqus_NV0NtQeEGq:disqus Incorrect. Your example generates an 8-digit integer. Stanley’s generates an 8-letter string. I too, hate correcting things that shouldn’t be said in the first place

  • nirajan

    laravel as much mature as rubyonrails

  • Rok Kralj

    Array.new(8) {(?a..?z).to_a.sample}.join

  • Dave Tan

    TEACH ME PLEASEEE…. =)

  • Abhinav M Kulkarni

    By the way, I really like the layout of your website. Can you please say if it is coded in PhP or RoR?

    • Good_Ole_Pinocchio

      Looks like PHP according to “Built it With” – Google it, good site to know.

    • leonardteo

      My blog is running WordPress, which is PHP.

  • Darragh Flynn

    Seems to be PHP, Husam.

    You should download this extension (https://chrome.google.com/webstore/detail/wappalyzer/gppongmhjkpfnbhagpmjfkannfbllamg?hl=en) called Wappalyzer if you use Chrome. It gives you a rough idea of what type of framework, language and libraries are being used by any given website. It can however be fooled by changing naming conventions in routing, but it’s a good base tool!

  • Milan Kubin
  • robertwilliams88

    If you had to start learning from scratch, would you start with Ruby or PHP?

    • leonardteo

      If you are learning specifically for web application development, I would advise to learn PHP first because you will get positive results much faster, that spurs you on to learn more. Ruby/Rails is great too, but unless you know the full stack (web server, databases, unix command line), you’ll struggle with it.

  • Good_Ole_Pinocchio

    There are good programs on (Paid)Codeschool, (Paid) Team Tree house (which I’m using now). (Free) Codecademy, which is a great place to start learning anything coding related.

  • AByrd

    Thanks so much for the information; it’s super helpful! And I’m so glad you came back with an update; it gives a nice perspective over a couple years.

  • riplash

    http://www.railstutorial.org/book

    I’ve been using this, it’s great, well written and easy to follow, and well regarded by people who train Rails devs.

  • Lorna Brain

    With this article my Leo you have done an emphatic job explaining these two technologies, for a new beauty like me wanting to get involved in web development; I have a blog I am creating and I want it to be more than that in the future – whereby I would provide data analysis and provide content data among other innovative stuff to do with my research. When I looked into Ruby I saw the ease of use to manipulate data, primarily the syntax was more encouraging unlike JS then I learned how Ruby is not effective manipulating DOM as I want to implement interaction here and there. ‘Unless’, I did not read the cue on this, if anyone or Leo could expand on this, that had be helpful.

    Because of this I have jumbled my languages between JavaScript and Ruby on Codecademy and LearnStreet and of course I am comfortable with CSS and HTML. I learn quick this way because the differentials of their complexity is where I build my motivation and wealth of knowledge. Although, I wish Ruby/Rails could be that language I could easily embed into HTML like JavaScript. Now I hear about “full stack”, oooh my…. for a beginner like me I am frozen.

  • Mubashir

    Thanks Leo for sharing useful information and your development experience with different languages. 🙂

  • Ben

    Hi, Leo. Thanks so much for writing this piece. I’m a beginner web developer still learning the ins and outs of back end technologies. I’ve used PHP and I’ve used RoR. I like them both very much. But your insights have helped me to decide to focus on PHP. Thanks, again. Such a great article.

  • x

    what exactly is the java of scripting language suppose to mean?

  • x

    $#t Da%@ how many random strings does the world need?!

  • Gato Preto

    Writing this in one line is not the way i’d do it in PHP.
    This reads much better:

    $s = ”;
    for ($i = 0; $i < 8; $i++) {
    $s .= chr(65 + rand(0, 25));
    }

    Even in ruby i could use 8.times and concat strings.

    s = ''
    8.times { s += (65 + rand(25)).chr }

    People are more familiar with imperative programming than functional, i think.

  • nice… now I’m interested to know more about Rails. I have zero knowledge in Ruby. 😀

  • Lucky Bhumkar

    Written from the soul. Very interesting experience..!

  • Shreyans Jain

    hi leonard I am from India this article is very useful

    I want some suggestions on building a big eCommerce website . I
    have a good experience of making website in asp.net ,asp.net Ajax and
    sql server 2008 . Now I am thinking about moving from Microsoft (because of cost) . Please
    help me choose between php(plain),php with mvc framework,django (not
    rails because of steep learning curve and updating the website after the
    host has updated the version).I have no experience on any of the above
    three.

    and I will develop alone and I want to cost to be on lower side.
    Any help would be useful

  • Dean

    Thanks for this article. As a programmer who’s been out of the loop for a while (no pun), I had suddenly been preached to about RoR by kids who had never been across other languages.. as if RoR was the be all and end all. Your article clarifies all the pros and cons very objectively. Much appreciated.

  • Hans

    As a would-be programmer starting out and slightly overwhelmed with all the languages and pressure with choosing one: really interesting article. Thanks!

  • Thanks for this Article.

    I’m using PHP (Laravel framework) for development and Codeception for automate testing. Should I try RoR ?
    I’ve heard that RoR have testing & deployment tool which help us saving time a lot.

    Do you have any recommends for me ?

    Thank you in advance !

  • Alberto Ferrer

    We can not compare a programming language with a framework for a programming language. If you don’t get this then you must start to learn again.

  • Matt

    A very well considered, helpful and well written article. Thank you Leo.

  • Robert H

    Just read your article. I started my developing ‘career’ in ASP.NET webforms, which was quite easy and then switch to MVC with scaffolding, razor, nuget, entity framework, jquery, etc. It seems to me that Microsoft’s stack is well-build and although I found it hard to learn MVC, it all fits together. Maybe they have ‘stolen’ all good ideas from other frameworks and languages but they combined them very well and build a great IDE. So why does no one use it these days? I read a lot of articles about what framework and language is the best, but they never compare it to ASP.NET. Is it ‘just’ because it’s Microsoft?

  • The best article i’ve ever read about ruby n php. Thanks for this!

  • Meanwhile, in Morocco:

    ('a'..'z').to_a.shuffle[0..7].join

  • Marco Zugaib

    Hi. I loved your blog and it helped me a lot. Thank you so much! I wanted to ask you one thing…
    My first Rails app is a mobile app that will start with almost 1 million users (from another app my company is buying) and also a web application, like Facebook that you use in the browser and on your iPhone. I don’t know how many nodes I can start with and I can’t find a lot of information online.
    We have one server (16 GB RAM) I am using to test load balancer, database replication… I can create as many VPS in the server as it fits in this server. I don’t know if 16 GB will be enough for 1 million users but I created 6 nodes for staging (and learn):
    – one with Nginx for load balancing (512MB)
    – two with Unicorn for the Rails application (1GB each)
    – two for MySQL (one master, one slave, but I still have to learn how to make Rails read from slave and write in the master, 2GB each)
    – one for files (512MB shared via NFS with the load balancers and apps, where paperclip will write).
    The database will have a lot of writes. What architecture configuration you recommend? Am I too wrong? I used small RAM because I will use more for production but I don’t know if 6 nodes is enough or if 16 GB will be enough. Can you help me? Thank you!

    • leonardteo

      1 million users who are logged in, or 1 million users per month who are mostly just browsing the site?
      Also, is the Rails application going to just be for an API or will it actually deliver the pages?

      It also depends on the memory footprint of your application, if it is large or not.

      1. 16GB is not likely enough for 1 million users if it is a reasonably sized application, and for that number of users I wouldn’t put everything on a single server anyway. I’d load balance across 2x 16GB (or 32GB) servers, quad cores minimum and scale from there. Remember, Ruby applications tend to bloat with lots of gems that you load in. The typical way to scale is to get as much memory as possible and run as many concurrent processes as you can in memory.

      2. I would not use Unicorn. It is flaky and consumes a lot of memory. For that kind of scale, I would use Passenger Enterprise. If you want to be cheap and not pay for the Passenger license (which is worth it), you can use Puma.

      3. For read replication, use Octopus gem (https://github.com/tchandy/octopus).

      4. Cache, cache, cache. Have one server just for Redis and cache the hell out of your application: http://guides.rubyonrails.org/caching_with_rails.html

      5. Move slow processes into Sidekiq for background processing.

      I wrote an article about scaling Rails apps here: http://www.ballistiq.com/2014/06/scaling-rails/

      • Marco Zugaib

        Thank you so much. It is 1 million users registered but usually 20,000 to 300,000 concurrent connections. And it’s HTML and JSON, depends of the extension. We want to grow, of course, so need to be ready to more.
        I thought Unicorn was the best. I was using memcached but I will try Redis.
        Thank you very much again. It was hard to find something online explaining how much memory and how many servers in the load balancer and things like this.

  • Puro Box

    Just think about this: if Facebook was done in PHP, which is probably the most robust and used web application in the planet, you don’t need to be a very smart person to realize php is far from being a bad programming language.

    in fact, PHP in the next 5 years will become the definitive best web programming language on top of every other one by far.
    Why ?

    Because its syntax is more human readable. The only reason why RoR is so trendy, is because it did very cool stuff a few years ago not available in php. But php is getting better day by day, frameworks like laravest are getting tremendous attention, and even bringing back old php users who are dropping RoR and coming back like prodigal sons.

    Yes, RoR deserves the credit of pioneering MVC and many other things, but it lacks the beauty and simplicity of C syntax, which will reign forever and ever.

    There’s a lot of hype regarding RoR, most people try RoR just because they want to feel trendy and cool, one of the reasons most hipsters use it. Don’t be a victim of the phenomenon. PHP is not a trendy thing, PHP, without all the noise and propaganda, still dominates the web.

  • Juan David Pastás Rivera

    Another alternative is Meteor, which is great, is a framework on top of node js, is the one I like the most from all that I have tried: derbyjs, deployd, sails, express, from what I remember. Even when it’s not comparable with Angular, Meteor supersedes it since you have 2 way data binding and backend logic at the same time and written in JavaScript, also you don’t have to learn ng attributes.

    PHP has Facebook as a great representative, but its syntax is not as simple as you can get with Meteor and preprocessing packages. Anyway, scaling is always another whole story, it’s a huge work which can be done in all languages/frameworks, I am not sure in which of them is easier though.

  • mindpower

    If that’s so then why does nobody choose to write apps in COBOL or BASIC anymore? Why would you choose CoffeeScript over Javascript? Why has Apple created Swift when people can just as well use Objective-C?

    Why does it take a non-speaker on average twice as long to learn Russian compared to Italian?

    To say it’s all about preferences and claim that somehow all languages are equal is pretty naive.

  • ifelse

    I like Php spent a lot of time learning it built most projects in Php and will continue doing so. The only reason I’m learning ROR now is because I get tons of job offers some remote. I look at it this way freelance jobs I’m using Php. Contract long term company jobs ROR I guess. I’m currently in between angularjs now because at my company we wanted to try this out with Ruby as the backend. So imagine the steep learning curve I’m going through for both of these languages Ruby and AngularJS at the same time.