CSC/ECE 517 Fall 2009/wiki1b 9 ad

From Expertiza_Wiki
Revision as of 19:31, 20 September 2009 by Prem (talk | contribs)
Jump to navigation Jump to search

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 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. Scaffolding is used to develop quick and simple interfaces during the initial stages of application development when the database schema is still shaping up.

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.


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.

CakePHP for PHP

CakePHP is a rapid development environment for PHP and uses commonly know design patterns like MVC and ORM. Unlike Rails 2 CakePHP supports dynamic scaffolding. Scaffolding in CakePHP is achieved by setting the $scaffold variable in the controller. The scaffolding feature 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.

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 can be tweaked to ones own liking. The one downside is Rails does not provide its own user authentication system, but there are plenty of plugins that implement that. Customization of the generic views in Django is possible but needs to be done manually.

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. 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.

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. 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 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..

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 tools and Freemarker templates to generate the front-end 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.

Resources