• Switching from PHP to Ruby on Rails

    Nov 30 2006

    Normally, I try to avoid server-side programming topics. But this time, I thought I'd share my story to perhaps inspire some of you to try something new.

    I switched to working in Ruby on Rails this month. Lots of people have done the switch, and even more have written about how Ruby on Rails makes coding web sites a lot more fun and easy (it's true!). But that's not what this story is about.

    Until I switched, I was a PHP programmer. It's not just that I did a lot of work in PHP, it's that this is what clients expected of me, or so I thought.

    Unfortunately, I was getting really bored of doing PHP programming. I've never been passionate about PHP, it's just something I know that I use to get the job done. Code Igniter had gotten me excited about coding in PHP again, but it just wasn't enough.

    I've had a lustful eye on Ruby on Rails since I first heard about it a year or two ago. Yet it stayed on my long-term To Do List, never quite becoming a reality. "When I have more time, I'll figure it out and start using it," I thought. "One of these days I'll do a small project for myself in Rails so I can learn it," I told myself for months.

    I felt like I was stuck. PHP was what I knew, what I had used for years, and what I was best at. I had never used Rails, so I certainly didn't feel qualified enough to sell myself as a Rails developer. On top of this, I had three major projects coming up that were all supposed to be done in PHP.

    Then one day, I asked myself why I was so willing and excited to work in JavaScript but not PHP. Why is one fun and the other painful? I had always thought of the difference as just client versus server, but then I figured out it might just be the language itself. So I decided the only way to keep my sanity was to switch. There was no way I would keep doing this PHP thing.

    So, I got in touch with my clients and asked if they'd be willing to build the projects with Ruby on Rails instead of PHP. They couldn't care less. All they wanted was the finished project, and it didn't matter to them how it was done. One client even said the only reason she had mentioned PHP was because it seemed like the most common, but really didn't care. They didn't even mind that I was just starting to learn, because they knew it would make the project more fun for me, and they trusted me.

    So I did it. I've been coding in Rails since the start of the month, and it's been a great time. Sure, there was a learning curve. It took me some time to figure out how to do the simplest of things. But I read through the book, I experimented, I searched the web for answers, and now I'm cruising. I'm about 80% as good in Rails as I am in PHP, except with Rails everything takes half the time so in the end it's actually faster.

    So what's the moral of the story? If there's something new you want to start doing, or if you're getting bored, just go change things. Today. Create your own opportunities. And stop finding excuses in those around you for your inability to change, because there's a good chance they will totally support you.

  • Comments

    1. Joel Birch at 8:23pm on November 30, 2006

    Very interesting - I'm trying to do the switch too. When you mention that you 'read the book', which book are you referring to? The pickaxe book? If so, isn't that book about the Ruby language itself and not Rails so much? Do you have any other tutorial or resource recommendations?

    Thanks for this post, I am so close to following your lead.

    2. Jesse Skinner at 8:33pm on November 30, 2006

    Ah, right, I was talking about "Agile Web Development with Rails" from the Pragmatic Programmers, which you can find online as a pdf:

    http://www.pragmaticprogrammer.com/titles/rails/

    I haven't read a book about Ruby (although this book has an Appendix on Ruby), but I have read over the documentation a lot at:

    http://www.ruby-doc.org/core/

    And once you're really working with Rails, you will certainly want to reference the API documentation (terrible for learning Rails, but excellent for looking up functions you already know about):

    http://api.rubyonrails.com/

    and occasionally I've found some good help on the wiki:

    http://wiki.rubyonrails.org/

    Hope that helps! Have fun!

    3. Joel Birch at 9:09pm on November 30, 2006

    Fantastic! Thanks for the links and such a quick response. "Agile Web Development with Rails" does look good.
    I found your site via Emil's recent blog post and I'm loving your content. Cheers.

    4. Joel Moss at 5:12am on December 1, 2006

    Great article Jesse. I have been debating the switch for ages now, but I still can't see why Rails is better, and why I can't achieve the same thing in PHP.

    Please read my blog post at http://joelmoss.info/switchboard/blog//2035:Developing_faster_with_Rails and let me know what you think.

    Should I switch?

    5. Anand at 6:26pm on January 3, 2007

    Great post!  You have taken the words right out of my mind.  I'm in a similar situation as you.  And I also found Code Igniter to be excellent, but not that comprehensive and somewhat lacking in features.  Right now, I'm mainating a CI based application as well as moving toward learning Rails.

    6. Chris at 4:08pm on January 18, 2007

    Jesse, thanks for your insight. I am just getting ready to pick a framework and, like you, have had my eye on Rails for a while, but am a PHP/Lasso programmer. As such, I have been looking at Code Ignitor, PHPCake and Symfony. So far Cake has my attention.

    I am wondering if you have further insight into what it is about Rails that won you over? Specifically what does it do that others (Cake, CI, etc ) don't?

    Thanks again.

    7. Jesse Skinner at 4:36pm on January 18, 2007

    There's a lot of overlapping functionality and features between Rails, Cake, Code Igniter, Symfony and any MVC framework. I'm not very familiar with Cake or Symfony, so I'm not sure what they offer. I do really like features in Rails like migrations, Active Record, generators, development/test/production modes, plus some of the features in the libraries like built-in validation in models.

    But I think what really sold me is the Ruby language itself. Ruby is an infinitely better language than PHP in the way it handles OOP, closures, regular expressions, as well as the syntax and data type functions.

    I've started to realise that PHP still has a place in the world. I'd never build a simple web site in Rails. It would be overkill. Rails is great when you have a complex database, but for a simple site with limited functionality (ie. contact form, guestbook), PHP is much easier.

    8. Anil Philip at 1:16pm on March 9, 2007

    If there's something new you want to start doing, or if you're getting bored, just go change things. Today. Create your own opportunities. And stop finding excuses in those around you for your inability to change...

    this was the takeaway for me. Thank you for an insightful comment.

    9. Jeff at 8:29pm on September 9, 2007

    Hey,

    I found this blog post on a google search. Thanks for the writing it - it was informative to me and also inspirational. I've been apprehensive about trying RoR for the same reasons you mention. I think it's time for me to take the plunge :)

    10. Mike at 12:08pm on October 15, 2007

    Hii,

    I've been using PHP for almost 4 years now and just a month ago I took a look at RoR and followed both the blog and flickr tutorial and really liked what I saw. Now I've read somewhere that all RoR web apps that are build by beginners usually contains a lot of garbage code. Is this just a myth? because I have a big project coming up and I can't wait to build it in RoR. What do you think?

    11. Jesse Skinner at 2:25pm on October 15, 2007

    @Mike - I found that there are a lot of really cool, slick, fast ways of doing things with Rails, most of which are totally not obvious. Probably the best way to learn these techniques is by reading books about Rails before you start programming. But of course, those who have more experience with Rails are going to write better, smarter code that takes advantage of all that Rails and Ruby have to offer.

    12. Alec at 2:01am on December 17, 2007

    Three questions:

    1. How hard is it to switch to RoR if

    - You don't know Ruby
    - You don't know OO

    I've written very complex stuff in PHP, but mostly procedural.

    2. Does RoR mean you don't have to work in JavaScript since it generates that?

    3. ORM or ActiveRecord is not as efficient performance-wise as a database proc. Can one continue to use those database proc's?

    13. Jesse Skinner at 9:12am on December 17, 2007

    @Alec -

    1a. You'll have to learn a whole new language. It's not a very hard language, but some concepts can be very tricky to understand at first.. and like learning any language, you'll have to look up basic functions, like how to work with strings and arrays, for the first few months at least.

    1b. Ruby on Rails is entirely OO based, so you'll need to understand the basics of OO, at least constructors, instance variables, inheritance, parent objects, methods, etc. This stuff isn't that difficult really, but it isn't obvious either.

    2. You can get away with not writing JavaScript if you want to do some simple things, but it won't do everything for you of course. And personally I'd rather do my own JavaScript than have it generated for me (but JavaScript is my expertise).

    3. I believe you can write direct SQL as much as you want, though I'm not sure how much extra work this would be.

    14. dicky at 4:13am on March 3, 2008

    Hi, i had go through a lot of article comparing RoR and PHP. I just want to ask 3 very simple questions. If i am a newbie to web programming (knowing little bit about PHP, HTML, CSS, and Javascript, but not RoR), which language should i choose?

    The second question is, i want to create a simple web application for user to share something with simple login/database, which language is most suitable to do so?

    The third question: I had go through the introduction of "Agile Web Development with Rails", but is it suitable for beginner? Or at least i need to know the basic of Ruby language?

    Thats all my question, hope someone can answer me...Thanks.

    15. Jesse Skinner at 11:37am on March 3, 2008

    @Dicky

    1. Well, you can learn anything you want really. If this is just something you're learning in your own time, then I'd suggest sticking with whatever you are most excited about. Explore PHP, explore Ruby on Rails, and use whichever one you enjoy working with more.

    2. I'd personally go with PHP and Code Igniter over Ruby on Rails for anything considerably simple.

    3. The Agile Web Development book(s) are aimed at people with little-to-no experience with Ruby or Rails. They assume you'll learn the Ruby language as you go (which you will). If you're new to programming this might be harder of course, but if you already know a few other languages it's not that hard to learn another new one.

    16. dicky at 6:53pm on March 3, 2008

    @Jesse: Thanks for your comments. I am a .NET programmer and now i am looking chances to got for web programming. Hope i can enjoy learning CodeIgniter. Thanks again!

    17. Summer A. Munir at 11:39pm on March 4, 2008

    Hi,

    My question is very simple and i think may be a very common one. Lately i had to leave my job and since then i am virtually doing nothing. Thought it would be better to learn programming. I got NO previous programming  experience. Although i am roughly familiar with certain programming concepts: i don't know CSS, PHP, VB, C# or any such thing. All i know to some extent is that logic prevails in computer sciences. However, at the same time i got sufficient user level exposure to state of the art softwares used in the banking sector. Question is: how long should it take for me to reach from point 0 to a professional programmer. Would it be months or years. I just want to earn some money and pretty desperate about it. Lately i've figured out that i am a kind of person who would prefer to sit alone and get his job done in front of a speecless computer:). Can you give me the timeline please and the best way to learn RoR? Thanks.

    18. Jesse Skinner at 10:26am on March 5, 2008

    @Summer - It's impossible to say how long it will take you to become a professional programmer, and even amongst professionals there is a wide range of skill and experience. It all depends on how quickly you learn and how much time you devote to it. That said, I don't think it would be unreasonable for someone to go from 0 to professional within a year if they really worked hard at it.

    As for learning RoR - the best way I know of is to work through the Agile Web Development book:

    http://www.pragprog.com/titles/rails2

    19. Summer A. Munir at 1:12am on March 6, 2008

    Thanks for your kind support. I think i should start with 4 hours a day. Let see where it goes. I will definitely go through the book suggested by you- it definitely seems good to begin with. Thanks once again.

    20. Aurelijus at 4:48am on March 17, 2008

    Why are you comparing programming language and framework ?

    By the way, what can you do with Ruby (programming language, not RoR framework) that you can't do with PHP ?

    21. kertz at 3:45am on May 25, 2008

    you're right... its stupid to compare PHP with RoR. PHP is powerful enough to do anything on web if you know it well... Tell me one good RoR application that works...

    22. Jim at 3:02pm on July 17, 2008

    Jesse,
    I have been in the networking world for some time (mcse) and moving to the ROR dev world. I have an app I would like to develop and market, I found various online video tutorials etc, it looks great.
    The question I have, which may be slightly ignorant, is this:
    I see how all the code works, querying the DB and displaying results etc, but how do you make it pretty? lol
    liquidplanner.com is a good example, all ROR, and looks great... Am I going to have to learn another IDE or CSS to get the overall feel of the site I am developing!

    Thanks!
    Jim

    23. Ravi Sagar at 3:33am on September 16, 2008

    Hey,

    I am also learning RoR. The book you mentioned doesn't go along with RoR v2.

    Can you also suggest some projects to work to grasp most of the useful features of RoR?

    24. nice designer at 5:07pm on October 2, 2009

    Hi Jesse,

    now after almost 3 years, I guess you're programming with RoR. Just wanted to ask you do you still like it? How did it help you? Did you learn the guts of Rails? I was looking for a good tutorial about the guts of the guts, so I was thrown here :) Fell free to email. Tnanx!

    25. Jesse Skinner at 10:10am on October 6, 2009

    @nice designer - actually I haven't personally used RoR for over a year. Ended up using PHP with CodeIgniter as my platform of choice. More on that here:

    http://www.thefutureoftheweb.com/blog/php-vs-ruby-on-rails-update

    26. Salil at 5:53am on January 18, 2010

    If your goal is better programming, you will learn far more from reading high-quality code bases in your current languages than from a new language. Go read top-notch code in the languages you know already; it’ll teach you techniques and style quickly, plus different ways of thinking about problems, with the added bonus that you can actually use what you learn. You can also understand a lot about programming languages in general (issues like typing, scoping, functional vs. imperative) by reading a good book.

    <http://duartes.org/gustavo/blog/post/language-dabbling-considered-wasteful>

    27. Yogesh at 6:03am on January 21, 2010

    Hi Jesse,
    I hav worked in J2EE for almost ! yera.
    Now I want to switch to Ruby, but before that I want to be assure that there is future in Ruby.
    hat you think about the future of this technology

    28. sakhunzai at 3:52am on February 24, 2010

    Good to hear !

    The problem with php is that non of the frameworks(php) provides a complete and consistent set of tools and techniques which could be re-used in other programming sphere.
    ROR is good choice , it gives what u need and it mature , it has great help and docs . 
        I ask myself , if I learn that framework, will I able to use that knowledge in some other domain ? Non of the php frameworks provide satisfactory answer  .

    29. SalmanK at 7:01am on March 19, 2010

    Wonderful article, thanks for inspiration. Ive just started learning JS and cant wait to move up to Ruby on Rails. Goodluck.

    30. Dan at 1:04pm on May 31, 2010

    This was a great article, thank you for writing it, this is actually the first time I have wanted to express my opinion in a forum so congratulations and sorry for any bad spelling.

    I will mainly talk about Ruby vs PHP and then give my personal recommendation, for web development, PHP or RoR. Sorry for the length of this comment and I hope this will be useful for other web developers, I guess this is as long as the article itself.

    First off and probably a little socking to some people is that PHP, JAVA and C++ are not actually object orientated languages, or at least not purely.

    A purely object orientated language must not contain primitive data types, like "int" in Java, C++. Also multiple inheritance must be able to be performed, on classes and interfaces, which in most apparently object orientated languages this cannot occur.

    Ruby is one of the only programming languages that is truely object orientated, everything is an object, even basic data types.

    Ruby is a more expressive and more of an agile programming language, and was created from the start for this purpose, such that less comments and even documentation need to be created in order to explain the code or concepts within the code.

    From a hackers perspective PHP is the most security flawed main stream web scripting language due to the inherent flaws of the language. Attacks such as SQL injections are nutorisiously easy to do in PHP, even if sanity checking has been done, which is partly due to how magic quotes work and how statements are created.

    I can't remember the name of the group that did it, if anyone would like to know, I would try to find out, but there was one stage not too long ago, maybe a year and a half where one group got fed up of the flaws in the PHP language and for one month they released a new hack a day for the PHP language, which finally after years of scrutiny got PHP developers working on trying to fix the language.

    One show of PHP developers trying to fix these issues (such as SQL injections) is the introduction of the PDO objects, which should be used when compared to mysql_ methods. PHP developers only started really fixing the language properly when they were embarrased by the hacks done by this group.

    Any method which is prefixed with mysql_ in the PHP library should be avoided where possible to avoid possible attacks.

    Though I like the PHP language and have used it for years in some cases, If I was to create a complex application with a lot of database transactions it would not be an ideal choice as databases usually contain alot of sensitive data, though the language is improving day by day now, unless you use the right libraries, you application will have many security flaws.

    Ruby is a language I have just began to use, but I can see the expressive power in the language, If you are a single developer, who creates their own web applications then ok PHP is fine to program in (forgetting it's security flaws), but if you program in an Agile way in PHP in a team, the code can become very hard to understand for new and existing developers, since PHP isn't very expressive.

    My recommendation would be to avoid PHP if you are working on a site which requires good security (or be very careful of the libraries you use) or if working in an Agile manner in a development team. If the site is going to be basic, then PHP is the better choice of language, but if many database transactions are to occur then RoR would be a faster and more secure route to take, since validation is always done for both server and client side operations, and SQL injections are alot less common, though not unheard of in RoR.

    The only downfall is the extra hardware which is required to keep a RoR application running compared with compilable languages (not PHP), but this is helped by the fact that less development resouces are needed so extra money can be spent on hardware anyway.

    31. Rishi Ghan at 2:50pm on September 24, 2010

    Hey Jesse,

    I am in the exact position that you were (PHP, contemplating RoR)
    I desperately want to make the switch and market myself as a RoR programmer. I also keep reading about how the future looks cloudy for RoR and it demotivates me to some extent.
    But after reading this, I am making the switch.

    Thanks for the article.
    Rishi

    32. Bryan Strader at 2:30pm on September 12, 2011

    Nice article, i too just made the switch, but from .Net. Been a week and I am just starting to get warmed up! :)

    Commenting is now closed. Come find me on Twitter.