7 Reasons I switched back to PhP after 2 years on rails

Source: Internet
Author: User
From: http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_ I _switched_back_to_p_1.html

By Derek Sivers in opinion

Summary:I spent two years trying to make rails do something it wasn' t meant to do, then realized my old abandoned Language(PHP, in my case)Wocould do just fine if approached with my new rails-gained wisdom.

Intro/background:

Back in January 2005, I announced on the O 'Reilly blog 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 aka bitsweat), and we set off on this huge task with intensity. the first few months showed good progress, and Jeremy cocould 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 do-able with a lot of glue. but it's damn hard. and certainly 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 mad skillz: Please 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 subversion respository.

ThenIn a mere two months, by myself, not even telling anyone I was doing this, using nothing but VI, 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.

Supported red 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. (get is only get. Any destructive actions require post .)

*-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 shoshould do what I 've ve done, I thought I shoshould share my reasons and lessons-learned, here:

Seven reasons I switched back to PhP after 2 years on rails:

#1-"Is there anything rails/Ruby can do that PHP can't do? ... (THINKING )... 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 cocould do anything in PHP, and there were begin 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 uugly PHP and replace it with beautiful PHP. Launch in stages. No big re-training.

#3-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 lamp 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 mod 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: 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 versions 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 uugly PHP code, compared to your new beautiful ruby code, and think, "God that PHP is uugly !" 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, dude. 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 uugly. if we only threw it all away and did it all over in rails, it 'd be so much easier!"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.