Sunday, February 15, 2009

Walking in the Rails

There are few popular PHP frameworks that made easier to PHP Programmers life like, Zend Framework, CodeIgnitor, Cake PHP etc. On the other hand, Rails is the best framework for Ruby. No doubt, I love PHP, and I am a Fan of rails as well. I wondered using various tools of rails to stand various web techniques in our web application (docVia) much easily. I assure you rails is much prettier than any PHP frameworks I have ever used. Now the fantasy is, I got a dam care mind against using PHP anymore, madly searching in google to see how brain stormers differs between PHP frameworks and rails. Finally, Amazingly and gradually I was coming down. All big bosses were differentiating between PHP (a scripting language) with rails (a framework on Ruby scripting language), while I was expecting differences between Zend framework or CakePHP with Rails framework. But did not get sufficient stuffs which distinguish between Rails framework and other PHP frameworks. Then, all I get is that rails makes programmers life much easier than PHP and Perl based frameworks, which at least consulates me. Basically, it is useless to find differences between PHP frameworks and rails. Theres huge arguments while anybody starts to gather differences between these. I tried to figure out what php frameworks can not do while a ruby framework-rails can do. I turned into a wise decision finally, that’s why I am not thinking to go against PHP rather I am trying here to focus rails as a friend of PHP programmers.

Objective of this article is to gradually introducing with the concepts of Rails to the PHP lovers so that they start liking rails.

Sometimes we need to decide which tool we should choose for a particular project, the key facts we need to think are as follows:

  • Size of app, particularly UI: large apps are easier with Rails
  • Size of team: small teams can do more with Rails
  • Quality of team: PHP is easier to work with
  • Need for change: changes are easier in Rails
  • Expected initial traffic: high-volume apps are easier in PHP

Few More Exciting Things that could let you to pick rails:

Migration
Besides these above matters there are few exciting things for what you might choose rails as a tool. Like, migration in rails is just wonderful. It’s migrationing system lets you sit behind relaxed. (Same thing, you might have in other tools, but I am not offending anyone else)

Scaffolding:
Scaffolding is a popular term in frameworks world. CakePHP and a few other PHP frameworks can do such stuffs as well but rails will give you much user friendly command line scaffolding and cool CRUD interface for any database structure. This is the starting, you will see how you become more relaxed accessing various gems* and plugins of rails. Instanlty, gems are small distribution packages which works with core rails system for all applications using rails to provide its coolest features.

RESTfull Rails:
Its alike an web service. Explicitly, it is not only a web service but a technology that extends HTTP into a new dimension, which optimizes and organizes the architecture. Rails provides RESTfull architecture. Exclusive thing is that from Rails version 2.0 it lets the RESTfull architecture with scaffolding.

Localization & Internalization:
It is integrated in Rails 2.0. Multilingual problems are nicely solved here.

Rails as a ruby framework:

Rails is a full-stack framework. Full-stack basically means that when you decide to use Rails it will provide practically all of the tools necessary all by itself. While you are welcome to use other tools for sections of Rails’ functionality, most current Rails developers are not (and for obvious reasons described below).

In Rails, we follow a mantra of “Convention Over Configuration.” With this in mind, Rails will follow industry conventions to make your job easier whenever possible. One example where you can see this in action is with page templates. *1

In Rails, if you have, for example, a BlogController and it has a method called list, Rails will automatically use the list.rhtml file inside of a folder called blog in your views folder. Not only that, but Rails will automatically pass on any instance variables you were using in the controller so that the view has access to them. *2

Now, when I am doing something similar in my own PHP apps, I have to manually instantiate the template object, manually pass references to any variables I know the view will be interested in and then manually tell it what template file to use. While all that manual code is pretty simple and easy to write, on even medium-sized apps it starts to take a toll on the leaness of the codebase. *3


Rails includes features that help in increasing developer productivity. Some of the main features include the followings: *5

  • MVC architecture: Ruby on Rails is based on the MVC (Model View Controller) architecture that enables the data to be separated from presentation.
  • Database Access Library: Ruby on Rails includes a database access library - Active Record - that simplifies data handling in databases. Active Record automatically maps tables to classes and rows to objects.
  • Database Relationships: One to many and many to many relationships can be easily implemented in rails.
  • Libraries for common tasks: Ruby on Rails includes a host of libraries that simplify the coding of common programming tasks such as form validations, sessions management, etc.
  • AJAX Library: An extensive library of AJAX functions is provided in the Rails framework. Ruby code can be used to generate AJAX code. The associated java scripting required for AJX gets generated automatically.
  • Convention over configuration: Ruby on Rails does not have any XML configuration files. It includes simple programming conventions that can be used to specify the configuration parameters.
  • Customized URL: Custom or Search Engine Friendly URLs can be developed using the Ruby on Rails framework.
  • Lines of code: Amazingly reduced huge number of lines of code which decreases code complexity.
  • RESTFull Rails: it is built in from Rails 2.
  • Testing: Testing is a wonderful feature in rails.
  • Debugging: Detailed error logs are provided, making it easier to debug applications.
  • Components: Components can be used to store reusable code. Components can be included to modularize templates.

Finally, Rails recent versions provide excellent REST full technology to secure the web apps and other facilities to make faster your web apps. Another great facility is to reduce time and size of any team while you try to build any application using rails. Unless learning Rails looks hard or there’s a huge marketing budget in place at launch, consider Rails.

–End–

References:

*1, *2, *3 : http://blog.clickablebliss.com/2005/12/24/php-vs-ruby-on-rails-part-1/
*4 : http://www.rbgrn.net/blog/2008/08/integrating-ruby-on-rails-with-existing-php-or-perl-based-si.html
*5 : http://www.linuxjournal.com/content/ruby-rails-features-railsonrubycom

http://www.igvita.com/2007/07/04/integrating-wordpress-and-rails/
http://blog.shlang.com/post/70877607/web-dev-rails-php


Glossary

Gem: A Gem is a packaged Ruby application using the packaging system defined by RubyGems. Installed in the Ruby or JRuby installation and is available to all applications run using that interpreter. Where, plugins are installed for any specified project scope.
http://weblogs.java.net/blog/arungupta/archive/2007/09/totd_6_differen.html

Framework: Concept of framework came while programmers try to get more organized in engineering way. It helps to build the concept of Shelf-Off term in Software Engineering. For example, Rails is a Ruby Framework. That means, using Ruby, there is an architecture on MVC, which is calles as Rails.

MVC: It is one of the leading famous framework technologies.

Rails: Rails was created in 2003 by David Heinemeier Hansson and has since been extended by the Rails core team, more than 1,400 contributors, and supported by a vibrant ecosystem

Ruby: Ruby is a scripting language like PHP, Perl etc. Targets of all these languages are almost same. The main difference between these language is, Ruby is fully Object Oriented while PHP and other language is not like that, they are merely Structure based. For example, the value ‘2′ is considered in Ruby as a Object, thus it has some identical properties as well, in instance, like 2.days.ago or something like that. In PHP, value ‘2′ might be considered as an integer or string, what it needs, whatever its just a value in PHP.

No comments:

Post a Comment