Yii vs. Rails
Gaurav Chande / March 12, 2012 (822 Words, 5 Minutes)
Yii vs. Ruby on Rails is something I have been trying to interpret since a long time now. After some failed attempts of asking this on forums, I thought, lets come back to this when I’ve worked with both.
I have been using Yii framework (since six months) on client projects and Ruby on Rails for personal projects. I started exploring Ruby a couple of months ago and been fiddling with Rails since a month. The fact that I can use both the frameworks easily (for different applications) almost everyday, gives us our first inference. The frameworks are not very different, at least for the most common tasks. They are trying to help us make web applications speedily, and they are doing it in much similar ways. In fact, Yii has credited Ruby on Rails for much of its ideas.
Both have features like ActiveRecord, MVC, I18N, Migrations, Scaffolding, Caching, Testing, etc. But, similarities don’t matter. Similarities cancel each other out. Differences will tell us why to choose one over the other.
The first main differentiating factor, and I cannot stress this enough, is the programming language behind these frameworks. The single biggest reason why Rails, or any other thing made using Ruby can be better, is because of the way things are done in Ruby language. I cannot even begin to explain how superior Ruby is to PHP (Why Ruby?). Just today at RubyConf India, Matz was quoted saying, ‘PHP is not a language, but a tool to solve simple problems’. It’s true that PHP is not a well-designed language. And this shows in the way things are done in Yii framework.
How does that quote go?
Winners dont do different things, they do things differently.
This is the second biggest difference. Rails does things differently. The methodology used in making features is extremely well-thought and superior in Ruby on Rails. This is again because of how Ruby language works. Whatever I do in Yii, I can do the same in Rails with less than half the code required and remain more organized. Less code doesn’t mean using ugly shortcuts. It means writing beautiful, smart, well structured code.
When I create a model using scaffolding in Yii, I get around 6 functions with approximately 100 lines of confusing code. You know how many lines of code I get when I generate a model in Rails? Zero. Does it make it less functional? No. I have the freedom to start writing details like relations and validation rules, which ought to be customized. (And what is with the auto generated
search() functions in Yii model anyway?)
Now lets look at the differences on a micro level. Things like Asset Pipeline, Helpers, Routing, Rails Console and Seeding available in Rails are tremendous, immensely useful. And these are only the features I have worked with yet. The first time I opened the ‘assets’ folder in my Yii app, I was shocked to having opened a dustbin instead. The ‘assets’ folder in Yii is a classic example of poorly organized method of solving a problem.
One area where Yii is a clear winner, is deployment. It’s a pain in the ass to deploy a Rails application for the first time (Capistrano or no Capistrano). But it is also true that once you’re through with it, doing it again is just a matter of a single command. Another area where Yii is really good is speed. Yii is very fast. Whether it is faster than Rails is debatable. After creating my first Rails application, Mircoblogging, I tried comparing its loading times with one of my Yii applications, Email Manager (something like MailChimp), using different methods. Rails app turned out to be faster.
My last parameter of comparison is community. Rails has one of the most vibrant OSS communities around. And it is one of the basic reasons why I decided to work using Ruby language and Rails. Having said that, Yii community has also been extremely helpful. And I do think Yii has some of the smartest PHP developers. One thing I have observed though, and I must point out, is that there is always a bunch of smart programmers moving from other technologies to Rails. I have seen comparatively fewer programmers moving from Rails to elsewhere.
Nevertheless, I would like to come to what my inner voice says. Despite hearing tons of times from other developers that choice of language/framework can make a difference, I would say, it doesn’t. It really does not. It is important, but not something that would automatically make you the best. What really matters is what you make using what you choose.
In last 8-10 months, after discovering my passion for creating software and starting to code, I’ve tried many different languages and jumped different platforms. This is the single most important observation I can think of: Choosing Yii over Rails, or Rails over Django does not hike up your chance of becoming the next Hacker of the Year. It has very little to do with what you actually make. Choosing “just a tool” like PHP and yet making something like Facebook (which they actually did of course), is something that matters.
Final Verdict: I would choose Rails over Yii. Not because it will suddenly make me a better programmer, but because it will make me a happier one. I love to write beautiful code in Ruby, and Rails enables me to do it. Again, if you choose something else, you are not doomed for failure. You have an equally good chance of creating something great. The only thing is, in my mind, you’ll be less happier, with somewhat shoddily designed code.
By the way, do you know how is Ruby on Rails defined by its creator?
Ruby on Rails is an open-source framework that’s optimized for programmer happiness and sustainable productivity. It lets you write beautiful code.
Programmer happiness. Think about it.