CSC/ECE 517 Fall 2009/wiki1b 9 ad: Difference between revisions
No edit summary |
No edit summary |
||
Line 57: | Line 57: | ||
[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. | [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. | ||
< | <i>Comparing RoR with Django</i> | ||
<ul> | <ul> |
Revision as of 21:08, 27 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 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.
How Dynamic Scaffolding was done in Rails
Run the script/generate command on a model and then use the migrate file, which is created to layout columns in the model's database table. Next run the script/generate command on a controller and then add scaffolding.
Code
class ContactController < ApplicationController scaffold contact # contact here is the name of the model called contact end
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
- 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.
- The code to generate scaffolds dynamically, is simple in most frameworks and a lot is accomplished in a single line of code.
Cons
- 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.
- The dynamic nature of generating scaffolds makes the behaviour of the application a little unpredictable.
- It is difficult to modify or customize the scaffold code since it is generated at run time.
The latest 'Scaffold code generator'
In Rails 2.0 it takes fewer steps than shown above, but may be a little harder to follow because so much is accomplished with so few commands.
ruby script/generate scaffold Model_Name [parameters]
This command accomplishes the task of generating the model, plus scaffolding, and the database migration script needed as well as a controller, helper, and testing support files.
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. 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.
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.
Comparison between 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
- Scaffold
- Scaffolding in Rails
- Scaffolding Step by step
- Scaffolding in MonoRail
- Active scaffold - RoR Plugin
- Dynamic Data support for Scaffolding
- CakePHP
- Seam-gen tutorial
- Grails vs Rails