Scaffold (programming)

From HandWiki
Short description: Code generation technique or a project generation technique

Scaffolding, as used in computing, refers to one of two techniques:

  • Code generation:

It is a technique related to database access in some model–view–controller frameworks.

  • Project generation:

It is a technique supported by various programming tools.

Code generation

Scaffolding is a technique supported by some model–view–controller frameworks, in which the programmer can specify how the application database may be used. The compiler or framework uses this specification, together with pre-defined code templates, to generate the final code that the application can use to create, read, update and delete database entries, effectively treating the templates as a "scaffold" on which to build a more powerful application.

Scaffolding is an evolution of database code generators from earlier development environments, such as Oracle's CASE Generator, and many other 4GL client-server software development products.

Scaffolding was made popular by the Ruby on Rails framework. It has been adapted to other software frameworks, including OutSystems Platform, Express Framework, Blitz.js, Play framework, Django, web2py, MonoRail, Brail, Symfony, Laravel, CodeIgniter, Yii, CakePHP, Phalcon PHP, Model-Glue, PRADO, Grails, Catalyst, Mojolicious, Seam Framework, Spring Roo, JHipster, ASP.NET Dynamic Data, KumbiaPHP and ASP.NET MVC framework's Metadata Template Helpers.

Run-time vs. design-time scaffolding

Scaffolding can occur at two different phases of the program lifecycle: design time and run time. Design time scaffolding produces files of code that can later be modified by the programmer to customize the way the application database is used. However, for large-scale applications this approach may be difficult to maintain due to the sheer number of files produced, and the fact that the design of the files was largely fixed when they were generated or copied from the original templates. Alternatively, run time scaffolding produces code on the fly. It allows changes to the design of the templates to be immediately reflected throughout the application. But modifying the design of the templates may be more difficult or impractical in the case of run time scaffolding.

Scaffolding in Ruby on Rails

When the line scaffold :model_name is added to a controller, Rails will automatically generate all of the appropriate data interfaces at run time. Since the API is generated on the fly, the programmer cannot easily modify the interfaces generated this way. Such a simple scaffold is often used for prototyping applications and entering test data into a database.

The programmer may also run an external command to generate Ruby code for the scaffold in advance: rails generate scaffold model_name. The generate script will produce files of Ruby code that the application can use to interact with the database. It is somewhat less convenient than dynamic scaffolding, but gives the programmer the flexibility of modifying and customizing the generated APIs.

Note: As of Rails 2.0, dynamic scaffolding is no longer stored.

Server side vs Client side Scaffolding

Scaffolding techniques based on the application database typically involve Server side frameworks. Server side web frameworks commonly perform operations directly against database entries, and code generation for these operations may be considered Server side Scaffolding. Alternatively, Client side development often uses frameworks that perform data transport operations instead of directly accessing the database. The focus of Client side Scaffolding is thus more on generating a starter template for the application as a whole, rather than generating code to access a database.

Some Client side web frameworks, such as Meteor, allow the client to perform database operations in a manner similar to Server side frameworks. In this case, Scaffolding techniques can go beyond merely generating a starter template. They can perform run time scaffolding of web forms on the Client side to create, read, update and delete database entries. One example of this is provided by an add-on to Meteor called aldeed:autoform.[1]

Project generation

Complicated software projects often share certain conventions on project structure and requirements. For example, they often have separate folders for source code, binaries and code tests, as well as files containing license agreements, release notes and contact information. To simplify the creation of projects following those conventions, "scaffolding" tools can automatically generate them at the beginning of each project. Such tools include Yeoman, Cargo and Ritchie CLI. For .NET projects, dotnet, the command-line tool included with the .NET SDK, can be used to scaffold new projects.

See also


References

External links