CSC/ECE 517 Summer 2008/wiki2 1 n1: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 30: Line 30:


===Framework Comparison===
===Framework Comparison===
Quote from the [http://us2.php.net/manual/en/preface.php preface of PHP manual]:
Quote from the preface of PHP manual:


<div style='margin-left:30px'>
''PHP is an HTML-embedded <b>scripting language</b>. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.''
''PHP is an HTML-embedded <b>scripting language</b>. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.''
</div>


indicates that PHP should not be compared directly to Ruby on Rails as a framework.  Instead comparison should be drawn between Ruby on Rails and various PHP frameworks, such as [http://framework.zend.com/ Zend Framework], [http://www.cakephp.org/ CakePHP], etc.
indicates that PHP should not be compared directly to Ruby on Rails as a framework.  Instead comparison should be drawn between Ruby on Rails and various PHP frameworks, such as [http://framework.zend.com/ Zend Framework], [http://www.cakephp.org/ CakePHP], etc.


Below are common features found in a well rounded web framework:
Below are common features found in a well rounded web framework:
*<b>MVC</b> - inbuilt support for Model-View-Controller setup.  Rails supports MVC by having the application structure with root folder \app, and four folders underneath, specifically \controllers, \helpers, \models, \views, and using a common convention to communicate between them.  
*<b>MVC</b> - built-in support for Model-View-Controller setup.  Rails supports and enforces MVC by having the application structure with root folder \app, and four folders underneath, specifically \controllers, \helpers, \models, \views.  Ruby uses common conventions to communicate between them.  
*<b>ORM</b> - support for object-record mapper.  For Rails, it is ActiveRecord.
*<b>ORM</b> - support for object-record mapper.  Rails' implementation of ORM is [http://ar.rubyonrails.com/ ActiveRecord].
*<b>Templates</b> - support for template engine.  Rails supports templating through render :partial, and yield.
*<b>Templates</b> - support for template engine.  Rails supports templating through [http://api.rubyonrails.org/classes/ActionController/Base.html#M000848 render :partial], and yield statements.
*<b>Caching</b> - Perhaps the most commonly used caching mechanism in Rails is caches_page method.
*<b>Caching</b> - Perhaps the most commonly used caching mechanism in Rails is caches_page method.
*<b>Validation</b> - built-in validation components.  ActiveRecord::Validations module in Rails offers useful validation methods.
*<b>Validation</b> - built-in validation components.  ActiveRecord::Validations module in Rails offers useful validation methods.
*<b>AJAX</b> - Rails inbuilt support for AJAX using Prototype Javascript Library is available in [http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html ActionView::Helpers::PrototypeHelper module].
*<b>AJAX</b> - Rails support AJAX using Prototype Javascript Library, and is available in [http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html ActionView::Helpers::PrototypeHelper module].


There are many PHP frameworks; not every PHP framework supports every one of these features above; please refer to [http://www.phpit.net/demo/framework%20comparison/chart.php PHP Framework Comparison Chart].  It is important to note that, Ruby on Rails gains popularity fast partially because it is a unified full stack framework for web development, and additional packages are supported through RubyGems.  Thus developers have the comfort of knowing their projects on Rails are well supported.  While several PHP frameworks have well-rounded set of features, it is more difficult for developers to determine which framework to use in the long run.   
There are over 40 PHP frameworks; not every PHP framework supports every feature above; please refer to [http://www.phpit.net/demo/framework%20comparison/chart.php PHP Framework Comparison Chart] for comparison on popular PHP frameworks.  It is important to note that, Ruby on Rails gains popularity fast partially because it is a unified full stack framework for web development, and additional packages are supported through RubyGems.  Thus developers have the comfort of knowing their projects on Rails are well supported.  While several PHP frameworks have well-rounded set of features, it is more difficult for developers to determine which framework to use in the long run.  However, advantage of PHP is that developers can opt not to use any PHP frameworks at all.  In fact, PHP by itself provides a large set of core library and gives developers the flexibility to use third-party modules or develop their own.  For instance, interaction with database can be done directly using low level API (see [http://us.php.net/manual/en/refs.database.php PHP Database Extensions]) or high level API commonly found in PHP frameworks. Similar to Rails, PHP supports [http://us.php.net/include/ include()] as basic templating mechanism, but developers can also use third-party template engines, such as [http://www.smarty.net/ Smarty]
 
Advantage of PHP is that developers can opt not to use any PHP frameworks at all.  In fact, PHP by itself provides a large set of core library and gives developers flexibility to use third-party modules or develop their own.  For instance, interaction with database can be done directly using low level API (see [http://us.php.net/manual/en/refs.database.php PHP Database Extensions]) or high level API commonly found in PHP frameworks.


===The Verdict===
===The Verdict===

Revision as of 01:30, 26 June 2008

While Ruby is fast growing in popularity, there are still more PHP Web applications communicating with MySQL dataases. Compare Rails with support for Web applications in PHP. Which are the advantages of each for the developer? For the finished application?

Rails vs. PHP

This document seeks to offer developers some insight on what Ruby on Rails and PHP offer, what are the advantages of each, and how they may be suitable for your next project. Note that PHP in this document refers specifically to PHP 5.

Language Comparison

As Ruby on Rails is built on Ruby, the comparison will be done between Ruby and PHP. Ruby is truly object oriented programming language. PHP also supports object oriented programming with Class and Object, but the following code examples of simple loop expression illustrates the different mindset required of developers for each language:

PHP

<?php
$array = array('item1', 'item2', 'item3');
foreach ($array as $index => $item) { echo "$index. $item"; }
?>

Ruby

<%
array = ['item1', 'item2', 'item3']
array.each_with_index { |item, index| puts "#{index}. #{item}" }
%>

Notice, the loop expression is called using an object in Ruby, whereas in PHP the loop is done through a construct. One can argue the two code segments accomplish the same goal; in this case it is purely personal preference. Ruby treats everything as object. Developers coming from Java or Perl will feel right at home with PHP, but may also find Ruby object oriented thinking refreshing and intuitive.

Another major difference is Ruby supports multiple inheritance via mixin, but does not support abstract or interface. PHP does not support multiple inheritance, but supports multiple interfaces like Java. Multiple inheritance is a powerful feature, but those used to develop in Java should get by with multiple interfaces just fine.

Other preferential differences worth mentioning:

  1. In Ruby, semicolon is not required after statements.
  2. Ruby supports the unless statement.
  3. Ruby block can be defined with the begin and end keywords.

Framework Comparison

Quote from the preface of PHP manual:

PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

indicates that PHP should not be compared directly to Ruby on Rails as a framework. Instead comparison should be drawn between Ruby on Rails and various PHP frameworks, such as Zend Framework, CakePHP, etc.

Below are common features found in a well rounded web framework:

  • MVC - built-in support for Model-View-Controller setup. Rails supports and enforces MVC by having the application structure with root folder \app, and four folders underneath, specifically \controllers, \helpers, \models, \views. Ruby uses common conventions to communicate between them.
  • ORM - support for object-record mapper. Rails' implementation of ORM is ActiveRecord.
  • Templates - support for template engine. Rails supports templating through render :partial, and yield statements.
  • Caching - Perhaps the most commonly used caching mechanism in Rails is caches_page method.
  • Validation - built-in validation components. ActiveRecord::Validations module in Rails offers useful validation methods.
  • AJAX - Rails support AJAX using Prototype Javascript Library, and is available in ActionView::Helpers::PrototypeHelper module.

There are over 40 PHP frameworks; not every PHP framework supports every feature above; please refer to PHP Framework Comparison Chart for comparison on popular PHP frameworks. It is important to note that, Ruby on Rails gains popularity fast partially because it is a unified full stack framework for web development, and additional packages are supported through RubyGems. Thus developers have the comfort of knowing their projects on Rails are well supported. While several PHP frameworks have well-rounded set of features, it is more difficult for developers to determine which framework to use in the long run. However, advantage of PHP is that developers can opt not to use any PHP frameworks at all. In fact, PHP by itself provides a large set of core library and gives developers the flexibility to use third-party modules or develop their own. For instance, interaction with database can be done directly using low level API (see PHP Database Extensions) or high level API commonly found in PHP frameworks. Similar to Rails, PHP supports include() as basic templating mechanism, but developers can also use third-party template engines, such as Smarty

The Verdict

PHP and Rails have their advantages. PHP offers flexible project structures and familiar coding style. Developers can opt to use third-party extensions or a PHP framework that further simplify development. Because developers can tailor PHP to their needs, PHP is often the more scalable solution for those who take their time to fine tune low level code and the use of third party extensions. Rails relies on standards and conventions to provide uniform development, which in turn allow new standards and packages to be adapted easily by Rails community. Projects that do not fit its strict conventions require extra effort from developers to make work.

Reference