7 reasons I switched back to PHP after 2 years on Rails
This was originally posted on O’Reilly in September 2007. Re-posting it here for a permanent archive.
SUMMARY: I spent two years trying to make Rails do something it wasn’t meant to do, then realized my old abandoned language would do just fine if approached with my new Rails-gained wisdom.
BACKGROUND:
Back in January 2005, I announced that I was going to completely scrap over 100,000 lines of messy PHP code in my existing CD Baby (cdbaby.com) website, and rewrite the entire thing in Rails, from scratch.
I hired one of the best Rails programmers in the world (Jeremy Kemper), and we set off on this huge task with intensity. The first few months showed good progress, and Jeremy could not have been more amazing, twisting the deep inner guts of Rails to make it do things it was never intended to do.
But at every step, it seemed our needs clashed with Rails’ preferences. Like trying to turn a train into a boat. It’s possible with a lot of glue. But it’s damn hard, and makes you ask why you’re really doing this.
Two years later, after various setbacks, we were less than halfway done. (To be fair to Jeremy’s expertise: many setbacks were because of tech emergencies that pulled our attention to other internal projects that were not the rewrite itself.) The entire music distribution world had changed, and we were still working on the same goddamn rewrite. I said fuckit, and we abandoned the Rails rewrite. Jeremy took a job with 37 Signals, and that was that.
I didn’t abandon the rewrite idea, though. I just asked myself one important question:
“Is there anything Rails can do, that PHP can’t do?”
The answer is no.
I threw away 2 years of Rails code, and opened a new empty project.
Then in a mere two months, by myself, not even telling anyone I was doing this, using nothing but vim, and no frameworks, I rewrote CD Baby from scratch in PHP. Done! Launched! And it works amazingly well.
It’s the most beautiful PHP I’ve ever written, all wonderfully MVC and DRY, and I owe it all to Rails.
Inspired by Rails:
- all logic is coming from the models, one per database table, like Martin Fowler’s Active Record pattern.
- no requires or includes needed, thanks to __autoload
- real MVC separation: controllers have no HTML or business-logic, and only use REST-approved HTTP.
- all HTML coming from a cute and powerful templating system I whipped up in 80 lines, all multi-lingual and caching and everything
- … and much more. In only 12,000 lines of code, including HTML templates. (Down from 90,000, before.)
Though I’m not saying other people should do what I’ve done, I thought I should share my reasons and lessons-learned, here:
7 reasons I switched back to PHP after 2 years on Rails:
#1 — “Is there anything Rails/Ruby can do that PHP can’t do? No.”
For 2 years, I thought Rails is genius, PHP is shit. Rails is powerful, PHP is crap. I was nearly killing my company in the name of blindly insisting Rails was the answer to all questions, timeframes be damned. But when I took a real emotionless non-prejudiced look at it, I realized the language didn’t matter that much. Ruby is prettier. Rails has nice shortcuts. But no big shortcuts I can’t code-up myself in a day if needed. Looked at from a real practical point of view, I could do anything in PHP, and there were many business reasons to do so.
#2 — Our entire company’s stuff was in PHP. Don’t underestimate integration.
By the old plan (ditching all PHP and doing it all in Rails), there was going to be this One Big Day, where our entire Intranet, Storefront, Members’ Login Area, and dozens of cron shell scripts were ALL going to have to change. 85 employees re-trained. All customers and clients calling up furious that One Big Day, with questions about the new system. Instead, I was able to slowly gut the ugly PHP and replace it with beautiful PHP. Launch in stages. No big re-training.
#3 — I don’t want what i don’t need
I admire the hell out of the Rails core gang that actually understand every line inside Rails itself. But I don’t. And I’m sure I will never use 90% of it. With my little self-made system, every line is only what’s absolutely necessary. That makes me extremely happy and comfortable.
#4 — It’s small and fast
One little 2U server is serving up a ton of cdbaby.com traffic damn fast with hardly any load.
#5 — It’s built to my tastes
I don’t need to adapt my ways to Rails. I tell PHP exactly what I want to do, the way I want to do it, and it doesn’t complain. I was having to hack-up Rails with all kinds of plugins and mods to get it to be the multi-lingual integration to our existing 95-table database. My new code was made just for me. The most efficient possible code to work with our exact needs.
#6 — I love SQL
Speaking of tastes: one tiny but important thing: I love SQL. I dream in queries. I think in tables. I was always fighting against Rails and its migrations hiding my beloved SQL from me.
#7 — Programming languages are like girlfriends. The new one is better because *you* are better
Rails was an amazing teacher. I loved it’s “do exactly as I say” paint-by-numbers framework that taught me some great guidelines. I love Ruby for making me really understand OOP. God, Ruby is so beautiful. I love you, Ruby. But the main reason that any programmer learning any new language thinks the new language is so much better than the old one is because he’s a better programmer now! You look back at your old ugly PHP code, compared to your new beautiful Ruby code, and think, “God that PHP is ugly!” But don’t forget you wrote that PHP years ago and are unfairly discriminating against it now. It’s not the language (entirely). It’s you. You’re better now. Give yourself some credit.
Ok. All that being said, I’m looking forward to using Rails some day when I start a brand new project from scratch, with Rails in mind from the beginning.
But I hope that this reaches someone somewhere thinking, “God our old code is ugly. If we only threw it all away and did it all over in Rails, it’d be so much easier!”
Hi. Correct link is http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html
Fixed. Thank you. — Derek
Is it true that you siwtched back again to Rails?
— Derek
From testimonial to the rails tutorial book.
http://ruby.railstutorial.org/
"My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP… This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on Rails Tutorial is what I used to switch back to Rails again… Though I’ve worked my way through many Rails books, this is the one that finally made me “get” it."
Yes, I've been using Ruby (with and without Rails) ever since leaving CD Baby, since reading the great Rails Tutorial book. CD Baby itself switched to who-knows-what after I left.
And which are the reasons for using Ruby now, instead of continuing with PHP ?
— Derek
I just like it.
Hello Derek,
I came across your "7 reasons I switched back to PHP after 2 years on Rails" (and some of the controversy around it) today, but unfortunately, the original blog entry on the O'Reilly site is no longer available (at least not under the link you give (http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html), and also not when searching for your name.
I'm very interested in what you had to say, not for the controversy, but for the substance. So I'd appreciate an updated pointer.
Regards, Martin.
Maybe it was temporarily down. I just tested and it's still working as of today (2013-05-22): http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html — Derek
"PROGRAMMING LANGUAGES ARE LIKE GIRLFRIENDS: THE NEW ONE IS BETTER BECAUSE *YOU* ARE BETTER"
This statement is the one thing that opened my eyes. I just had one of those "Oh My... you're absolutely RIGHT!!!"
I have been studying Rails for a month now after coming from being a PHP dev who never touches frameworks. After 1 month I have a bazillion ideas who to write better PHP code. Hence, the aforementioned statement really hit home!
☺ Awesome. So nice to hear, after all these years. Thank you. — Derek
So for someone starting out today, 2015, what would you recommend that they learn? PHP or Ruby on Rails?
JavaScript,">sive.rs/learn-js">JavaScript, definitely. — Derek
Hello Derek, if you would start CDBaby today, would you use PHP or RoR?
Elixir + Phoenix — Derek
hi, if i understand correctly your site is cdbaby.com
and is asp.net....
I remembered and re-read this post after seeing this meme today: i.imgur.com/BiM3GJ0.png
I read this post during reading the book “Hell yes or no”
Hi Derek!
I hope you're doing well!
If you were to kickstart CD Baby today in 2023, which tech stack do you think you'd lean towards: PHP, RoR, Elixir, or Next.js? 😊
Elixir + Phoenix — Derek
Llegue aquí leyendo el libro, interesante testimonio. ¿Crees que Ruby on Rails ahora es mejor que hace muchos años?
Si. — Derek