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

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:
What needs to be stressed is that Rails is a framework and PHP is a language. Because of this discrepancy, many of the comparisons made in this document are not Rails to PHP comparisons, they are Ruby to PHP comparisons. Luckily this doesn't derail us too much. And now we can proceed with the topic at hand.
What needs to be stressed is that Rails is a framework and PHP is a language. Because of this discrepancy, many of the comparisons made in this document are not Rails to PHP comparisons, they are Ruby to PHP comparisons. Luckily this doesn't derail us too much. And now we can proceed with the topic at hand.


== Advantages for the developer ==
== Ruby on Rails Advantages for the Developer ==
=== Ruby on Rails ===
=== Rails is easy to develop ===
==== Rails is easy to develop ====
One common comment about Ruby on Rails is that it is a very easy language to pick up and develop in for a beginner. With the [http://instantrails.rubyforge.org/wiki/wiki.pl Instant Rails] package a developer can go from nothing to something in a matter of minutes. Ruby also provides very nice and organized [http://www.ruby-lang.org/en/documentation/ documentation] for any level of developer.
One common comment about Ruby on Rails is that it is a very easy language to pick up and develop in for a beginner. With the [http://instantrails.rubyforge.org/wiki/wiki.pl Instant Rails] package a developer can go from nothing to something in a matter of minutes. Ruby also provides very nice and organized [http://www.ruby-lang.org/en/documentation/ documentation] for any level of developer.
==== The Rails framework is much more organized than base PHP ====
=== The Rails framework is much more organized than base PHP ===
Rails is based on an [http://en.wikipedia.org/wiki/Model-view-controller Model, View, Controller (MVC)] architecture. The basic organization of MVC is as follows:
Rails is based on an [http://en.wikipedia.org/wiki/Model-view-controller Model, View, Controller (MVC)] architecture. The basic organization of MVC is as follows:
* Models handle database interaction
* Models handle database interaction
* Controllers handle processing of input stimulus
* Controllers handle processing of input stimulus
* Views provide the interface
* Views provide the interface
==== Rapid prototyping ====
=== Rapid prototyping ===
To create a new Rails based web application and set up the basic layout of the MVC architecture, Rails only need be given a single command.
To create a new Rails based web application and set up the basic layout of the MVC architecture, Rails only need be given a single command.
  rails <app_name>
  rails <app_name>
Creating new controllers, models, and views is no more difficult than the creation of the base architecture. All of these operations can be done with a single command and Rails will create the basis for the developer to add to. This makes prototyping an idea very quick.
Creating new controllers, models, and views is no more difficult than the creation of the base architecture. All of these operations can be done with a single command and Rails will create the basis for the developer to add to. This makes prototyping an idea very quick.
==== Many operations in Ruby and 'nicer' than in PHP ====
=== Many operations in Ruby and 'nicer' than in PHP ===
Many operations that take multiple instructions in PHP can be done with one in Ruby.
Many operations that take multiple instructions in PHP can be done with one in Ruby.
Example 1: Iteration
Example 1: Iteration
Line 32: Line 31:
<pre>
<pre>
</pre>
</pre>
==== Rails makes the switching databases very easy ====
=== Rails makes the switching databases very easy ===
Rails can be configured to work with virtually any relational database on the market today. Switching databases is as simple as changing one configuration file (''database.yml'') and executing one command (''rake db:migrate''). This can be done because Rails uses [http://api.rubyonrails.org/classes/ActiveRecord/Migration.html migrations]. A migration allows you to specify the tables, their contents, and their relationships to be created/modified/destroyed in a database.
Rails can be configured to work with virtually any relational database on the market today. Switching databases is as simple as changing one configuration file (''database.yml'') and executing one command (''rake db:migrate''). This can be done because Rails uses [http://api.rubyonrails.org/classes/ActiveRecord/Migration.html migrations]. A migration allows you to specify the tables, their contents, and their relationships to be created/modified/destroyed in a database.
==== Ruby is the epitome of OO ====
=== Ruby is the epitome of OO ===
** Everything in Ruby is an object, everything.  
** Everything in Ruby is an object, everything.  
** Ruby was specifically built around this principle.  
** Ruby was specifically built around this principle.  
** This doesn't seem too big a deal unless it is also pointed out than many PHP sites still employ PHP4 which is very outdated and its OO support is shoddy at best.
** This doesn't seem too big a deal unless it is also pointed out than many PHP sites still employ PHP4 which is very outdated and its OO support is shoddy at best.
==== Creation of tests is much easier ====  
=== Creation of tests is much easier ===  
Whenever you create a new Rails web application, the base testing framework is included in the layout. Whenever you add a model, view, or controller via a command an empty test is created for the component you just added. Since Rails has migrations to do its databases, the creation of a testing database is very quickly done. This way mock database objects do not have to be created and you do not need to test against a live or development database.
Whenever you create a new Rails web application, the base testing framework is included in the layout. Whenever you add a model, view, or controller via a command an empty test is created for the component you just added. Since Rails has migrations to do its databases, the creation of a testing database is very quickly done. This way mock database objects do not have to be created and you do not need to test against a live or development database.
==== Rails can make you a better programmer ====
=== Rails can make you a better programmer ===
While using Rails does not guarantee that you will become a better programmer, it does introduce some techniques and concepts that are useful for developers to learn, to know, and to use. The testing ability of Rails is one of the best things for a developer to take away from the framework. Many developers neglect the importance of testing and many times create errors that are uncaught because of this neglect.  
While using Rails does not guarantee that you will become a better programmer, it does introduce some techniques and concepts that are useful for developers to learn, to know, and to use. The testing ability of Rails is one of the best things for a developer to take away from the framework. Many developers neglect the importance of testing and many times create errors that are uncaught because of this neglect.  
The other most useful takeaway from Rails is the MVC architecture itself. The architecture is very good for organizing concepts logically instead of throwing code in random places to simply get a program to work.
The other most useful takeaway from Rails is the MVC architecture itself. The architecture is very good for organizing concepts logically instead of throwing code in random places to simply get a program to work.


=== PHP ===
== Ruby on Rails Advantages for the Finished Application ==
==== PHP has much larger community support ====
* Rails is easy to maintain
** The framework helps a lot because you know exactly where to look for the functionality that you need to add to or revise.
** Rails is very readable and easy to pick up. You can eyeball code and know what it does.
** Changing databases is easy.
 
== PHP Advantages for the Developer ==
=== PHP has much larger community support ===
The single biggest argument for PHP over Rails has to be PHP's availability of code snippets, assistance, and documentation. [http://www.php.net/manual/en/ PHP's documentation] on their site is extensive, descriptive, and community supported. Though not a scientific comparison, [http://google.com/trends?q=php%2C+rails%2C+ruby&ctab=0&geo=all&date=all&sort=0 Google Trends] paints a very clean picture of usage of PHP over Rails and Ruby.  
The single biggest argument for PHP over Rails has to be PHP's availability of code snippets, assistance, and documentation. [http://www.php.net/manual/en/ PHP's documentation] on their site is extensive, descriptive, and community supported. Though not a scientific comparison, [http://google.com/trends?q=php%2C+rails%2C+ruby&ctab=0&geo=all&date=all&sort=0 Google Trends] paints a very clean picture of usage of PHP over Rails and Ruby.  
==== PHP can have the MVC architecture too ====
=== PHP can have the MVC architecture too ===
Because of the huge user base many people have derived their own frameworks like [http://www.cakephp.org/ CakePHP] and [http://www.zend.com/en/community/framework Zend Framework] that provide you what you think you may miss by straying away from Rails. [http://www.railsenvy.com/2007/8/24/rails-vs-php Rails has criticized CakePHP] for mimicking the exact architecture of Rails. This is not a bad thing though. Rails has a good thing in its MVC architecture and this criticism does nothing if not reiterate how well the MVC architecture can be done with PHP.
Because of the huge user base many people have derived their own frameworks like [http://www.cakephp.org/ CakePHP] and [http://www.zend.com/en/community/framework Zend Framework] that provide you what you think you may miss by straying away from Rails. [http://www.railsenvy.com/2007/8/24/rails-vs-php Rails has criticized CakePHP] for mimicking the exact architecture of Rails. This is not a bad thing though. Rails has a good thing in its MVC architecture and this criticism does nothing if not reiterate how well the MVC architecture can be done with PHP.
==== With PHP the developer has more control ====
=== With PHP the developer has more control ===
With PHP you are not stuck with the MVC architecture. There are not many arguments against the MVC architecture as it does teach good practices, but there is one very big one. MVC architecture may be very overwhelming for very small and simple sites. In the case of a simple site, MVC adds a bunch of unnecessary bloat.
With PHP you are not stuck with the MVC architecture. There are not many arguments against the MVC architecture as it does teach good practices, but there is one very big one. MVC architecture may be very overwhelming for very small and simple sites. In the case of a simple site, MVC adds a bunch of unnecessary bloat.
==== PHP looks familiar for many developers ====
=== PHP looks familiar for many developers ===
Many developers do not get their start in Ruby or PHP, they get their start in a language like C, C++, or Java because that is what is taught in school. PHP's syntax is very similar to all three of these languages whereas Ruby's is much different looking.
Many developers do not get their start in Ruby or PHP, they get their start in a language like C, C++, or Java because that is what is taught in school. PHP's syntax is very similar to all three of these languages whereas Ruby's is much different looking.
C++ Class:
C++ Class:
Line 84: Line 89:
end
end
</pre>
</pre>
==== PHP has a enormous function set (and *nix users already know a lot of it) ====
=== PHP has a enormous function set (and *nix users already know a lot of it) ===
PHP has an absolutely enormous [http://us2.php.net/quickref.php function set]. Many of these commands are taken directly from the *nix command set and brought in to PHP. For developers this means that a lot of functionality is already done for you, don't reinvent the wheel. For developers who are also *nix users this means that you probably already know what function you are looking for without digging for it.
PHP has an absolutely enormous [http://us2.php.net/quickref.php function set]. Many of these commands are taken directly from the *nix command set and brought in to PHP. For developers this means that a lot of functionality is already done for you, don't reinvent the wheel. For developers who are also *nix users this means that you probably already know what function you are looking for without digging for it.
Examples of *nix instructions in PHP: ''mkdir'', ''md5'', ''copy'', ''date'', and the list goes on.
Examples of *nix instructions in PHP: ''mkdir'', ''md5'', ''copy'', ''date'', and the list goes on.
==== More customizable ====
=== More customizable ===
You can build your software a la cart. Take a piece of this code, take a piece from that code, mix, viola! New application!
You can build your software a la cart. Take a piece of this code, take a piece from that code, mix, viola! New application!


== Advantages for the finished application ==
== PHP Advantages for the Finished Application ==
=== Ruby on Rails ===
* Rails is easy to maintain
** The framework helps a lot because you know exactly where to look for the functionality that you need to add to or revise.
** Rails is very readable and easy to pick up. You can eyeball code and know what it does.
** Changing databases is easy.
 
=== PHP ===
* PHP scales much more easily
* PHP scales much more easily
** PHP is less CPU and Memory intensive requiring less hardware to accomplish the same task
** PHP is less CPU and Memory intensive requiring less hardware to accomplish the same task

Revision as of 18:50, 4 July 2008

Rails vs PHP

While Ruby is fast growing in popularity, there are still more PHP Web applications communicating with MySQL databases. 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 is an unfair comparison

I feel that I must start off with a cliche comparision: comparing Rails to PHP is like comparing apples to oranges. With straight quotes from the front pages of their respective web sites I will demonstrate what I mean:

  • Rails - Ruby on Rails is an open source web framework...
  • Ruby - Ruby is a dynamic, open source programming language...
  • PHP - PHP is a widely-used general-purpose scripting language...

What needs to be stressed is that Rails is a framework and PHP is a language. Because of this discrepancy, many of the comparisons made in this document are not Rails to PHP comparisons, they are Ruby to PHP comparisons. Luckily this doesn't derail us too much. And now we can proceed with the topic at hand.

Ruby on Rails Advantages for the Developer

Rails is easy to develop

One common comment about Ruby on Rails is that it is a very easy language to pick up and develop in for a beginner. With the Instant Rails package a developer can go from nothing to something in a matter of minutes. Ruby also provides very nice and organized documentation for any level of developer.

The Rails framework is much more organized than base PHP

Rails is based on an Model, View, Controller (MVC) architecture. The basic organization of MVC is as follows:

  • Models handle database interaction
  • Controllers handle processing of input stimulus
  • Views provide the interface

Rapid prototyping

To create a new Rails based web application and set up the basic layout of the MVC architecture, Rails only need be given a single command.

rails <app_name>

Creating new controllers, models, and views is no more difficult than the creation of the base architecture. All of these operations can be done with a single command and Rails will create the basis for the developer to add to. This makes prototyping an idea very quick.

Many operations in Ruby and 'nicer' than in PHP

Many operations that take multiple instructions in PHP can be done with one in Ruby. Example 1: Iteration


Example 2:


Rails makes the switching databases very easy

Rails can be configured to work with virtually any relational database on the market today. Switching databases is as simple as changing one configuration file (database.yml) and executing one command (rake db:migrate). This can be done because Rails uses migrations. A migration allows you to specify the tables, their contents, and their relationships to be created/modified/destroyed in a database.

Ruby is the epitome of OO

    • Everything in Ruby is an object, everything.
    • Ruby was specifically built around this principle.
    • This doesn't seem too big a deal unless it is also pointed out than many PHP sites still employ PHP4 which is very outdated and its OO support is shoddy at best.

Creation of tests is much easier

Whenever you create a new Rails web application, the base testing framework is included in the layout. Whenever you add a model, view, or controller via a command an empty test is created for the component you just added. Since Rails has migrations to do its databases, the creation of a testing database is very quickly done. This way mock database objects do not have to be created and you do not need to test against a live or development database.

Rails can make you a better programmer

While using Rails does not guarantee that you will become a better programmer, it does introduce some techniques and concepts that are useful for developers to learn, to know, and to use. The testing ability of Rails is one of the best things for a developer to take away from the framework. Many developers neglect the importance of testing and many times create errors that are uncaught because of this neglect. The other most useful takeaway from Rails is the MVC architecture itself. The architecture is very good for organizing concepts logically instead of throwing code in random places to simply get a program to work.

Ruby on Rails Advantages for the Finished Application

  • Rails is easy to maintain
    • The framework helps a lot because you know exactly where to look for the functionality that you need to add to or revise.
    • Rails is very readable and easy to pick up. You can eyeball code and know what it does.
    • Changing databases is easy.

PHP Advantages for the Developer

PHP has much larger community support

The single biggest argument for PHP over Rails has to be PHP's availability of code snippets, assistance, and documentation. PHP's documentation on their site is extensive, descriptive, and community supported. Though not a scientific comparison, Google Trends paints a very clean picture of usage of PHP over Rails and Ruby.

PHP can have the MVC architecture too

Because of the huge user base many people have derived their own frameworks like CakePHP and Zend Framework that provide you what you think you may miss by straying away from Rails. Rails has criticized CakePHP for mimicking the exact architecture of Rails. This is not a bad thing though. Rails has a good thing in its MVC architecture and this criticism does nothing if not reiterate how well the MVC architecture can be done with PHP.

With PHP the developer has more control

With PHP you are not stuck with the MVC architecture. There are not many arguments against the MVC architecture as it does teach good practices, but there is one very big one. MVC architecture may be very overwhelming for very small and simple sites. In the case of a simple site, MVC adds a bunch of unnecessary bloat.

PHP looks familiar for many developers

Many developers do not get their start in Ruby or PHP, they get their start in a language like C, C++, or Java because that is what is taught in school. PHP's syntax is very similar to all three of these languages whereas Ruby's is much different looking. C++ Class:

class person
{
private:
  int age;
public:
  int GetAge() { return age; }
  void SetAge(int i) { age = i; }
};

PHP Class:

class person
{
  private age;
  public int GetAge() { return this->age; }
  public void SetAge(i) { age = i; }
}

Ruby Class:

class person
  def GetAge
    @age
  end
  def SetAge(i)
    @age = i
  end
end

PHP has a enormous function set (and *nix users already know a lot of it)

PHP has an absolutely enormous function set. Many of these commands are taken directly from the *nix command set and brought in to PHP. For developers this means that a lot of functionality is already done for you, don't reinvent the wheel. For developers who are also *nix users this means that you probably already know what function you are looking for without digging for it. Examples of *nix instructions in PHP: mkdir, md5, copy, date, and the list goes on.

More customizable

You can build your software a la cart. Take a piece of this code, take a piece from that code, mix, viola! New application!

PHP Advantages for the Finished Application

  • PHP scales much more easily
    • PHP is less CPU and Memory intensive requiring less hardware to accomplish the same task
  • PHP is faster
  • PHP is easier to deploy
    • It is actually rather difficult to find a hosting service that does not support PHP. While some may only have PHP4 support, most hosts support PHP5. When the time comes it is also very easy to move from you development system to a host.
    • PHP hosting a very inexpensive comparatively.
    • You only need FTP access, no need for SSH access.
    • Rails hosting? What is that? Finally found it! It costs how much?!?!?! I can't just use FTP?!?!?!

References