How Modern Code Generation Works

In the recent years, web applications have seen dramatic enhancements in the features and user experience, and this has raised the bar for all kinds of software applications. Even the corporate management expects that their internally developed applications should include the latest features, and also support industry standard technologies and platforms. To meet these raised expectations, the developers come under tremendous pressure to produce the best in the least possible time. Businesses are limiting budgets, and shrinking in head counts. In the midst of limited resources and mounting expectations, the developers must find ways to improve productivity, reduce development backlog and migrate projects to the latest technology standards.

With such pressing conditions, writing unnecessary code is painful, and a waste of time. It can be quite unproductive for any organisation to use senior development resources to work on time-intensive, low-level hand coding tasks. At the same time, there is usually insufficient junior staff, and even when they are available, they may not be trained enough for coding or code reviews.

IT departments can address these problems by investing in reliable tools that are easy to use and can automate and manage the development process. Application generators are the code generation tools that offer significant advantages. Application generator helps create application programs that can run on a particular platform. These generators take basic set of inputs and jumpstart the application development process by generating basic code which is more bug-free and reliable as compared to the hand-written code. This also makes the testing and bug-fixing much easier. Sophisticated application generators deliver code which is consistent with the pre-decided set of functionality. Additionally, these generators can generate complex web pages including reports, forms, filter and several other advanced navigation features. The generated code is comparable to the one written by the senior developers. Passive code generators create code and then have nothing to do with the project. Active code generators create code and keep track of the generated code during its lifecycle. The modern code generators are capable of:

  • 1. Starting from scratch with an application-specific data model
  • 2. Creating comprehensive functional applications that link everything and deliver executable, bug-free applications as a base
  • 3. Generating source code native to the target environment or platform
  • 4. Providing easily modifiable and well-organised source code
  • 5. Preserving customizations and modifications during subsequent application regenerations

Modern code generators mainly fall into three categories:

  • Templating– One-shot code generation, supported in editors and IDEs to some extent and code can be easily edited
  • Round-Tripping– Code is generated to be edited and the edited code can be re-imported into the generator
  • Compiling– Binary code or source code generated is not intended to be edited

Additionally, code generators can also be classified as:

Database Script Generators – They write incremental script to create and update relational database model based on the given model.

Application source code generators – Create code in any particular programming language to work with the database. The generated code includes classes to manage database access and to publish the access layer as Web service.

Code generation process is iterative, developers can add databound controls, user interface pages and databases tables to the application in any order. The generated base classes can be customized, and existing or third party code assets can be imbedded. Effects of changes can be easily seen by just regenerating the application at any time. With each new iteration, all the extensions and customizations are automatically preserved. Some of the most commonly used code generation tools are:

  • 1. Acceleo- An open source code generator that allows developers to use model-driven approach for building applications. It provides tools for code generation from EMF based models, and allows incremental generation so that users can generate a piece of code, modify the generated code and regenerate the code without losing previous modifications. Acceleo allows code generation from any kind of metamodel compatible with EMF like UML1, 2 etc. It also allows customization of the generation with the user defined templates and generation of any textual language such as Java, C, Python, etc
  • 2. Actifsource- A model driven software development to create any graphical editor for the domain models. A comprehensive design and code generator tool that covers domain driven software development. It is Eclipse-based, multi-user graphical tool, and offers sophisticated multi-model support
  • 3. Altova MapForce – Any-to-any graphical data mapping, conversion and integration tool which maps data between any combination of database, XML, XBRL, EDI, EXCEL, flat file, JSON or Web service. It instantly transforms data or auto-generates data integration code
  • 4. Spring Roo- Easy to use productivity tool, it is much more than a code generator. The code is automatically changed when changes are made to the Entities. User just needs to give commands, and Spring Roo does the rest
  • 5. RISE- A software application that operates on a RISE model and produces some kind of output. RISE model contains entire life-cycle of the data model, and code generator translates this into an incremental database specific scripts. Additionally, RISE supports C#(.NET) and PHP
  • 6. MyGeneration- Fairly straightforward, flexible and simple tool written in Microsfot .NET. It is good for generating code for ORM architectures. The database metadata is available to the templates through MyMeta API
  • 7. CodeSmith Generator- Template driven source code generator that automates the creation for application source code for any language (Java, C#, PHP, VB, .NET< SQL etc.)

Few other code generation tools are Visual Paradigm and Netbeans IDE to generate code from UML, and Netbeans IDE and MS Visual Studio for editing/generating GUIs.

Modern code generation tools can help develop code for today’s complex applications framework. These generators produce high-quality output which is maintainable and consistent. Code generation tools abstract the code design, and multiple outputs can be generated from a single application functionality model. This also relieves the development team so that they can focus on other strategic-issues and high-level design work. These tools help reduce the time and cost of development.