CSC/ECE 517 Fall 2009/wiki1b 9 ad: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(101 intermediate revisions by 2 users not shown)
Line 2: Line 2:




Scaffolding is a meta-programming method of building database-backed software applications. It is a technique that allows a programmer to quickly generate a skeleton interface, which allows the user to perform basic CRUD ( Create Read Update Delete) operations on the application's database. The auto-generated interface can then be modified to perform more powerful tasks.
<p>Scaffolding is a [http://en.wikipedia.org/wiki/Metaprogramming meta-programming] method of building database-backed software applications. It is a technique that allows a programmer to quickly generate a skeleton user interface for an application. This interface then allows the user to perform basic CRUD ( Create Read Update Delete) operations on the application's database. The auto-generated interface can then be modified to perform more powerful tasks.</p>
<p>The concept of scaffolding was made popular by the [http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] framework with its dynamic scaffolding. Dynamic Scaffolding enabled programmers to develop quick and simple interfaces on the go during the initial stages of application development, when the database schema is still shaping up.</p>
 
==Dynamic Scaffolding==
Dynamic Scaffolding is a method of generating scaffolds at run time or on the fly. Dynamic scaffolding can be achieved by placing the keyword ''scaffold'' with the model name in the controller class as shown below.
<pre>
class ContactController < ApplicationController
scaffold contact    # contact here is the name of the model called contact
end
</pre>
 
When this code is executed Rails generates all the appropriate data interfaces. Dynamic scaffolding was removed in Rails 2 and replaced by a generator of scaffolds.


== Why was dynamic scaffolding removed in Rails 2? ==
== Why was dynamic scaffolding removed in Rails 2? ==
Dynamic Scaffolding of Rails 1.x was replaced by a generator of scaffolds in Rails 2.  
Dynamic Scaffolding of Rails 1.x was replaced by a generator of scaffolds in Rails 2. [http://en.wikipedia.org/wiki/David_Heinemeier_Hansson David Heinemeier Hansson] [http://www.ruby-forum.com/topic/151197#667127 responding] to a new rails developer on a Ruby forum said,


<p>[http://en.wikipedia.org/wiki/David_Heinemeier_Hansson David Heinemeier Hansson] [http://www.ruby-forum.com/topic/151197#667127 responding] to a new rails developer on a Ruby forum said "Dynamic Scaffolding didn't really help people learn about Rails or give them a way to modify the generated interface, so we killed it.".</p>
<p><i>"Dynamic Scaffolding didn't really help people learn about Rails or give them a way to modify the generated interface, so we killed it.".</i></p>
<p>In dynamic scaffolding when the line ''scaffold :model_name '' is added to the controller ruby automatically generates the appropriate interfaces at run time. Since, scaffolding is implemented on the fly the programmer cannot easily modify and customize the interfaces.Therefore, dynamic scaffolding was removed in Rails 2 though it is still available as a plugin.</p>
<p>In dynamic scaffolding when the line <code>scaffold :model_name</code> is added to the controller rails automatically generates the appropriate interfaces at run time. Since, scaffolding is implemented on the fly the programmer cannot easily modify and customize the interfaces.Therefore, dynamic scaffolding was removed in Rails 2 though it is still available as a plugin.</p>


== Pros and cons of Dynamic Scaffolding ==
== Pros and cons of Dynamic Scaffolding ==
Line 25: Line 36:
</ol>
</ol>


==The generator of Scaffolds ==
The generator of scaffold takes the name of the model ''ie'' the resource and optionally a list of field names and types as shown below in the command line and automatically adds the appropriate data interfaces to the application.
<pre>
cmd> ruby script/generate scaffold modelname \ field1:type field2:type ....
</pre>
Unlike dynamic scaffolding the scaffold generator generates the scaffolds explicitly. One drawback to this is that the model cannot be updated automatically when a new field is added to the table. The programmer will have to run the ''script generate/scaffold''
command or manually update the model.


== Scaffolding in frameworks for other languages ==
== Scaffolding in frameworks for other languages ==


Many other languages such as Java, .NET, PHP, Python have frameworks that have adapted scaffolding. Let us walk through some of the frameworks that provide the scaffolding feature such as CakePHP, Codelgniter, Symphony and Yii for PHP, Django for Python, MonoRail and for .Net and Seam for Java.
Many other languages such as Java, .NET languages, PHP, Python have frameworks that have adapted scaffolding. Let us walk through some of the frameworks that provide the scaffolding feature such as CakePHP, Codelgniter, Symphony and Yii for PHP, Django for Python, MonoRail and ASP.net for .Net, Seam for Java and Grails for Groovy.


<h4>CakePHP for PHP</h4>
<h4>CakePHP for PHP</h4>
Scaffolding in CakePHP is
<p>CakePHP is a rapid development environment for PHP and uses commonly known design patterns like [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC] and [http://en.wikipedia.org/wiki/Object-relational_mapping ORM]. It is modeled after the concepts of Ruby on Rails and hence has many similarities with it.
Scaffolding in CakePHP is implemented by adding the $scaffold variable in the controller:</p>
<pre>
<?
php class ContactController extends AppController
{   
  var $scaffold;
}
?>
</pre>
 
<h5>Comparing RoR with CakePHP</h5>
<ul>
<li>Unlike Rails 2 CakePHP supports dynamic scaffolding.</li>
<li>Just like RoR the scaffolding feature in CakePHP analyzes the database tables and creates standard lists with add, delete and edit buttons, standard forms for editing and standard views for inspecting a single item in the database.</li>
</ul>
 


<h4>Django for Python</h4>
<h4>Django for Python</h4>
Django is an open source web application framework, written in Python, which follows the model-view-controller architectural pattern.  Just like Rails, Django aims at providing the concept of 'DRY' and extensive reusability. With regard to scaffolding, once the models are defined, Django can automatically create a professional and production ready administrative interface -- a Web site that lets authenticated users add, change and delete objects. The framework offers role-based authentication and also one does not have to deal with creating backend interfaces just to manage content. It uses generic views to help automate CRUD operations that rails scaffold provides, minus the html generation.  
[http://www.djangoproject.com/ Django] is an open source web application framework, written in Python, which follows the model-view-controller architectural pattern.  Just like Rails, Django aims at providing the concept of [http://en.wikipedia.org/wiki/Don't_repeat_yourself 'DRY'] and extensive reusability. With regard to scaffolding, once the models are defined, Django can automatically create a professional and production ready administrative interface -- a Web site that lets authenticated users add, change and delete objects. The framework offers role-based authentication and also one does not have to deal with creating backend interfaces just to manage content. It uses generic views to help automate CRUD operations that rails scaffold provides, minus the html generation.
 
<h5>Comparing RoR with Django</h5>
 
<ul>
<li>Customization of the generic views in Django is not done automatically.</li>
<li>Rails does not provide its own user authentication system, however, there are custom plugins that implement this feature. </li>
</ul>


When compared with Rails, Rails is slightly faster because of its scaffolding feature which generates some html as well as the model-interaction code, which you can then tweak to your own liking. The one downside is Rails doesn't provide its own user auth system, but there are plenty of plugins that implement that. Customization of the generic views in Django is possible but you kind of have to hack around the blackbox or implement it yourself.


<h4>MonoRail for .net</h4>
<h4>MonoRail for .net</h4>
MonoRail, a component of the Castle Project, is an open source web application framework built on top of the ASP.NET platform. Scaffolding like Ruby on Rails (RoR), controllers adorned with the necessary scaffolding attributes can automatically produce the basic markup and logic for CRUD operations on the domain model. It proves handy for prototyping or creating rough-and-ready data entry capabilities in your applications in no time. It is flexible upto an extent that its implementation allows you to override the views if you want, so the scaffolding will handle only the CRUD. Importantly, the framework lets you design your classes that generate your database, rather than designing your database to create your classes. MonoRail, just like Rails, maintains a standard for data access throughout its applications.
[http://www.castleproject.org/monorail/gettingstarted/index.html MonoRail], a component of the Castle Project, is an open source web application framework built on top of the ASP.NET platform. Like scaffolding in Ruby on Rails (RoR), controllers adorned with the necessary scaffolding attributes can automatically produce the basic markup and logic for CRUD operations on the domain model. It proves handy for prototyping or creating rough-and-ready data entry capabilities in your applications.  
 
<h5>Comparing RoR with MonoRail</h5>
 
<ul>
<li>MonoRail gives the flexibility to chalk out responsibilities that should be handled by Scaffolding. i.e., Its implementation allows you to override the views if you want, and the scaffolding will handle only the CRUD operations.  
</li><li>Both MonoRail and RoR let you design your classes that generate your database, rather than generating your classes from a given database schema.
</li><li>MonoRail, just like Rails, maintains a standard ORM for data access throughout its applications.</li></ul>
 


<h4>ASP.net Dynamic Data</h4>
<h4>ASP.net Dynamic Data</h4>


ASP.NET Dynamic Data Support, a part of the [http://www.infoq.com/news/2007/12/aspnet-35-extensions-dec2007ctp ASP.NET 3.5 Extensions] project provides a rich scaffolding framework that allows rapid data driven site development using both ASP.NET WebForms and ASP.NET MVC. Dynamic Data lets you run a scaffolded web application on top of your schema with minimal efforts. Just like the other frameworks, customization of views is possible. It includes a .NET Attribute approach, which might be used to add formatting or range validation to the data model directly. Unlike Rails, Dynamic Data has no specific [http://en.wikipedia.org/wiki/Object-relational_mapping ORM] of choice to access data. It provides numerous ways with a few to name like MSFT, ADO .NET - the MS Entity framework, LINQ to SQL, etc..
ASP.NET Dynamic Data Support, a part of the [http://www.infoq.com/news/2007/12/aspnet-35-extensions-dec2007ctp ASP.NET 3.5 Extensions] project provides a rich scaffolding framework that allows rapid data driven site development using both ASP.NET WebForms and ASP.NET MVC. By default ASP.NET Dynamic Data projects provide built-in support for creating automatic "scaffolding" views of LINQ to SQL and LINQ to Entities data models.  Dynamic Data projects include template pages and user controls that can do CRUD operations are dynamically constructed at runtime based on the LINQ to SQL or LINQ to Entities data model that has been added to the project.
 
<h5>Comparing RoR with ASP.net Dynamic Data</h5>
 
<ul><li>
Unlike Rails' dynamic scaffolding, customization of views is possible. </li><li>It includes a .NET Attribute approach, which might be used to add formatting or range validation to the data model directly. </li><li>As against Rails, Dynamic Data has no specific choice of [http://en.wikipedia.org/wiki/Object-relational_mapping ORM] to access data. Any ORM like ADO .NET - the Entity framework, NHibernate etc. could be used.</li></ul>
 


<h4>Seam for Java</h4>
<h4>Seam for Java</h4>


Seam is a powerful open source development platform for building rich Internet applications in Java. It provides a scaffolding code generation tool called seam-gen. Seam-gen allows the developer to begin developing a custom application without having to spend time piecing together the build, configuration, and dependencies. It makes use of Hibernate tools and Freemarker templates to generate the front-end [http://en.wikipedia.org/wiki/JavaServer_Faces JSF] code as well as Java classes required by the application. The java classes implement Home design pattern which is much cleaner than the ActiveRecord design pattern used in Rails as it separates out the object and operations. Code generation in Seam-gen requires few configurations as against the Rails' ''"script/generate"'' single line command, which simply works.
[http://seamframework.org/ Seam] is a powerful open source development platform for building rich Internet applications in Java. It provides a scaffolding code generation tool called seam-gen. Seam-gen allows the developer to begin developing a custom application without having to spend time piecing together the build, configuration, and dependencies. It makes use of Hibernate ORM tools and Freemarker templates to generate the front-end [http://en.wikipedia.org/wiki/JavaServer_Faces JSF] code as well as Java classes required by the application.  
 
<h5>Comparing RoR with Seam</h5>
 
<ul>
<li>Code generation in Seam-gen requires a couple of configuration steps whereas Rails accomplishes the same with the'single line command ("script/generate").</li>
<li>The java classes implement Home design pattern which is much cleaner than the ActiveRecord design pattern used in Rails as it separates out the object and operations.</li>
</ul>
 
 
<h4>Grails for Groovy</h4>
 
[http://www.springsource.com/products/grails Grails], is a [http://en.wikipedia.org/wiki/Web_application_framework#Push-based_vs._Pull-based push] MVC web framework just like Rails but it uses the [http://groovy.codehaus.org/ Groovy] language.
 
<h5>Comparing RoR with Grails</h5>
 
<ul><li>
Grails offers the Implicit Dynamic Scaffolding (optional) feature, as against Rails, which does not offer it anymore. This can be useful when learning the framework.</li><li> The view (html) is generated, and adapts automatically to the changes in the model like Rails.</li><li> Both frameworks also have explicit scaffolding. </li><li>The scaffold generated by Rails is more elegant, but Grails has the extra feature of column sorting.</li></ul>
 


== Resources ==
== Resources ==
Line 53: Line 128:
<ul>
<ul>
<li>[http://en.wikipedia.org/wiki/Scaffold_(programming) Scaffold]</li>
<li>[http://en.wikipedia.org/wiki/Scaffold_(programming) Scaffold]</li>
<li>[http://momotaro.biz/Ruby-on-Rails/0596101325/rubyrails-CHP-4-SECT-1.html Scaffolding in Rails]</li>
<li>[http://www.tutorialspoint.com/ruby-on-rails/rails-scaffolding.htm Scaffolding in Rails]</li>
<li>[http://www.ryandoom.com/Blog/tabid/57/articleType/ArticleView/articleId/42/ASP-NET-MVC-vs-Monorail-Castle-Project.aspx ASP-NET-MVC-vs-Monorail-Castle-Project]</li>
<li>[http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html Scaffolding Step by step]</li>
<li>[http://www.infoq.com/news/2007/12/aspnet-dynamic-data Dynamic Data Overview]</li>
<li>[http://www.castleproject.org/monorail/documentation/trunk/integration/arscaffold.html Scaffolding in MonoRail]</li>
<li>[http://activescaffold.com/2007/5/24/how-to-approach-active-scaffold Active scaffold - RoR Plugin]</li>
<li>[http://weblogs.asp.net/scottgu/archive/2007/12/14/new-asp-net-dynamic-data-support.aspx Dynamic Data support for Scaffolding]</li>
<li>[http://cakephp.org/ CakePHP]</li>
<li>[http://docs.jboss.org/seam/1.1GA/reference/en/html/gettingstarted.html Seam-gen tutorial]</li>
<li>[http://docs.jboss.org/seam/1.1GA/reference/en/html/gettingstarted.html Seam-gen tutorial]</li>
<li>[http://www.jtict.com/blog/grails-vs-rails/ Grails vs Rails]</li>
</ul>
== Abbreviations ==
<ul>
<li>[http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD - Create, Read, Update & Delete]</li>
<li>[http://en.wikipedia.org/wiki/Object-relational_mapping ORM - Object Relational Mapping]</li>
<li>[http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC - Model View Controller]</li>
<li>[http://rubyonrails.org/ RoR - Ruby on Rails]</li>
<li>[http://msdn.microsoft.com/en-us/netframework/aa904594.aspx LINQ - Language INtegrated Query]</li>
</ul>
</ul>

Latest revision as of 01:22, 29 September 2009

Scaffold

Scaffolding is a meta-programming method of building database-backed software applications. It is a technique that allows a programmer to quickly generate a skeleton user interface for an application. This interface then allows the user to perform basic CRUD ( Create Read Update Delete) operations on the application's database. The auto-generated interface can then be modified to perform more powerful tasks.

The concept of scaffolding was made popular by the Rails framework with its dynamic scaffolding. Dynamic Scaffolding enabled programmers to develop quick and simple interfaces on the go during the initial stages of application development, when the database schema is still shaping up.

Dynamic Scaffolding

Dynamic Scaffolding is a method of generating scaffolds at run time or on the fly. Dynamic scaffolding can be achieved by placing the keyword scaffold with the model name in the controller class as shown below.

class ContactController < ApplicationController
scaffold contact     # contact here is the name of the model called contact
end

When this code is executed Rails generates all the appropriate data interfaces. Dynamic scaffolding was removed in Rails 2 and replaced by a generator of scaffolds.

Why was dynamic scaffolding removed in Rails 2?

Dynamic Scaffolding of Rails 1.x was replaced by a generator of scaffolds in Rails 2. David Heinemeier Hansson responding to a new rails developer on a Ruby forum said,

"Dynamic Scaffolding didn't really help people learn about Rails or give them a way to modify the generated interface, so we killed it.".

In dynamic scaffolding when the line scaffold :model_name is added to the controller rails automatically generates the appropriate interfaces at run time. Since, scaffolding is implemented on the fly the programmer cannot easily modify and customize the interfaces.Therefore, dynamic scaffolding was removed in Rails 2 though it is still available as a plugin.

Pros and cons of Dynamic Scaffolding

Pros

  1. The biggest advantage of Dynamic scaffolding is that it allows the programmer to extend and modify the database schema without worrying about extra coding to reflect those changes in the interface. The user interface automatically updates to keep up with the changes.
  2. The code to generate scaffolds dynamically, is simple in most frameworks and a lot is accomplished in a single line of code.

Cons

  1. The biggest disadvantage of Dynamic scaffolding is that the programmer cannot see whats going on. Since all the interfaces are generated on the fly, the code is hidden; this could be especially disadvantageous to someone who is trying to learn Rails.
  2. The dynamic nature of generating scaffolds makes the behaviour of the application a little unpredictable.
  3. It is difficult to modify or customize the scaffold code since it is generated at run time.

The generator of Scaffolds

The generator of scaffold takes the name of the model ie the resource and optionally a list of field names and types as shown below in the command line and automatically adds the appropriate data interfaces to the application.

cmd> ruby script/generate scaffold modelname \ field1:type field2:type ....

Unlike dynamic scaffolding the scaffold generator generates the scaffolds explicitly. One drawback to this is that the model cannot be updated automatically when a new field is added to the table. The programmer will have to run the script generate/scaffold command or manually update the model.

Scaffolding in frameworks for other languages

Many other languages such as Java, .NET languages, PHP, Python have frameworks that have adapted scaffolding. Let us walk through some of the frameworks that provide the scaffolding feature such as CakePHP, Codelgniter, Symphony and Yii for PHP, Django for Python, MonoRail and ASP.net for .Net, Seam for Java and Grails for Groovy.

CakePHP for PHP

CakePHP is a rapid development environment for PHP and uses commonly known design patterns like MVC and ORM. It is modeled after the concepts of Ruby on Rails and hence has many similarities with it. Scaffolding in CakePHP is implemented by adding the $scaffold variable in the controller:

<?
php class ContactController extends AppController 
{     
   var $scaffold; 
} 
?> 
Comparing RoR with CakePHP
  • Unlike Rails 2 CakePHP supports dynamic scaffolding.
  • Just like RoR the scaffolding feature in CakePHP analyzes the database tables and creates standard lists with add, delete and edit buttons, standard forms for editing and standard views for inspecting a single item in the database.


Django for Python

Django is an open source web application framework, written in Python, which follows the model-view-controller architectural pattern. Just like Rails, Django aims at providing the concept of 'DRY' and extensive reusability. With regard to scaffolding, once the models are defined, Django can automatically create a professional and production ready administrative interface -- a Web site that lets authenticated users add, change and delete objects. The framework offers role-based authentication and also one does not have to deal with creating backend interfaces just to manage content. It uses generic views to help automate CRUD operations that rails scaffold provides, minus the html generation.

Comparing RoR with Django
  • Customization of the generic views in Django is not done automatically.
  • Rails does not provide its own user authentication system, however, there are custom plugins that implement this feature.


MonoRail for .net

MonoRail, a component of the Castle Project, is an open source web application framework built on top of the ASP.NET platform. Like scaffolding in Ruby on Rails (RoR), controllers adorned with the necessary scaffolding attributes can automatically produce the basic markup and logic for CRUD operations on the domain model. It proves handy for prototyping or creating rough-and-ready data entry capabilities in your applications.

Comparing RoR with MonoRail
  • MonoRail gives the flexibility to chalk out responsibilities that should be handled by Scaffolding. i.e., Its implementation allows you to override the views if you want, and the scaffolding will handle only the CRUD operations.
  • Both MonoRail and RoR let you design your classes that generate your database, rather than generating your classes from a given database schema.
  • MonoRail, just like Rails, maintains a standard ORM for data access throughout its applications.


ASP.net Dynamic Data

ASP.NET Dynamic Data Support, a part of the ASP.NET 3.5 Extensions project provides a rich scaffolding framework that allows rapid data driven site development using both ASP.NET WebForms and ASP.NET MVC. By default ASP.NET Dynamic Data projects provide built-in support for creating automatic "scaffolding" views of LINQ to SQL and LINQ to Entities data models. Dynamic Data projects include template pages and user controls that can do CRUD operations are dynamically constructed at runtime based on the LINQ to SQL or LINQ to Entities data model that has been added to the project.

Comparing RoR with ASP.net Dynamic Data
  • Unlike Rails' dynamic scaffolding, customization of views is possible.
  • It includes a .NET Attribute approach, which might be used to add formatting or range validation to the data model directly.
  • As against Rails, Dynamic Data has no specific choice of ORM to access data. Any ORM like ADO .NET - the Entity framework, NHibernate etc. could be used.


Seam for Java

Seam is a powerful open source development platform for building rich Internet applications in Java. It provides a scaffolding code generation tool called seam-gen. Seam-gen allows the developer to begin developing a custom application without having to spend time piecing together the build, configuration, and dependencies. It makes use of Hibernate ORM tools and Freemarker templates to generate the front-end JSF code as well as Java classes required by the application.

Comparing RoR with Seam
  • Code generation in Seam-gen requires a couple of configuration steps whereas Rails accomplishes the same with the'single line command ("script/generate").
  • The java classes implement Home design pattern which is much cleaner than the ActiveRecord design pattern used in Rails as it separates out the object and operations.


Grails for Groovy

Grails, is a push MVC web framework just like Rails but it uses the Groovy language.

Comparing RoR with Grails
  • Grails offers the Implicit Dynamic Scaffolding (optional) feature, as against Rails, which does not offer it anymore. This can be useful when learning the framework.
  • The view (html) is generated, and adapts automatically to the changes in the model like Rails.
  • Both frameworks also have explicit scaffolding.
  • The scaffold generated by Rails is more elegant, but Grails has the extra feature of column sorting.


Resources

Abbreviations