Skip to Content

Code generation… Can it be simple and pragmatic?

Sogeti Labs
August 06, 2013

+33 (0) 6 07 73 34 07 laurent.guerin@sogeti.comWhen “code generation” is mentioned, usually everyone thinks about “Model Driven Development”.  MDD is a “Model First” approach and it implies that a model has been designed at the beginning of the project.  Different kinds of models can be used as input for the generator, but very often a classical UML model is used. Obviously in MDD the model is fundamental. This approach is a good solution if you have enough time and resources to design a reliable an accurate model, and while you continue to use the model as the reference in the development lifecycle. However, it requires a significant workload. Hence it’s a long term and strategic choice.

CodeGeneration1

Another option is to try to generate the code from an existing database. In this case, the database structure (tables, columns, etc) is used as the unique source of information by the generator. This is a “Database First” approach. It has been made popular by Ruby On Rails. It’s known as the “scaffolding” principle and it’s used with different languages and frameworks (Ruby/Ruby On Rails,  Groovy /GRAILS,  PHP/CakePHP or Symphony,   etc..). Hence, it’s very efficient and it allows a rapid start without any model design. With such a tool, you can start your project very quickly. But there are some limitations in this approach…  The tool must work with what it has and nothing else…  And it doesn’t have a lot of information. So this approach is quite limited. It can be considered as a tactical choice.

CodeGeneration2

So, do I have to choose between a too heavy approach and a too limited one? Another approach can be considered, it is based on a mix between the “Database First” and the “MDD”. The principle can be described by 3 steps :
  1. An existing database is used to create a “lightweight model”. The structure of the database is retrieved by the tool as in a “scaffolding” principle but to create a simple model and not to generate the code immediately
  2. Once the model has been created, it can be updated and complemented in order to provide exactly what is expected  for the code generation
  3. Finally, the customized “lightweight model” can be used by the tool to generate the code (usually by applying templates)
CodeGeneration3 This approach has been implemented by the research and development team of Sogeti France and it is used as a “development accelerator” in different kinds of projects. It provides an efficient way to improve the productivity, especially with short-cycle projects (time to market, etc). It is available as an Open Source Eclipse Plugin. For more information, see :

About the author

SogetiLabs gathers distinguished technology leaders from around the Sogeti world. It is an initiative explaining not how IT works, but what IT means for business.

    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *