Skip to content

Best practices for generator development

Axel Guckelsberger edited this page Sep 11, 2024 · 5 revisions

This page is about development of the generator, not for building applications with the generated code.

Development process

An approach suggested often for MDSD projects is an iterative-incremental and especially agile development process. This process is divided into two threads:

  • domain architecture development
  • application development

Regarding the first one we are splitting work on the tool chain into two parts again:

  • one team from the toolchain start: dsl design, meta models, validation constraints, tooling
  • one team from the toolchain end: Zikula core/platform development, generator improvements

Bidirectional communication flows between both threads are essential

  • upcoming dsl evolvements and lifecycles
  • reference implementation snippets + required/desired language evolvements
  • agreement about lifecycles and priorities/order of bigger amendments

Generator development

Beauty and understandable code

Generator code must follow the same coding guidelines and design pattern as usual. It should be understandable for the devs working with it.

Separating generated and manual code

The generator uses some kind of generation gap where empty classes inherit from base classes containing the generated code.

Testing generator cartridges with reference models

All artifacts of the domain achitecture, like code generators, model validation and model transformations must be tested automatically, too. To ensure that the generated code behaves like required we can create unit tests for it. Therefore we have to create reference models using the DSLs concept as example. Ideally each element is named according to the aspect it is representing, in order to reach full coverage of all aspects and variabilities. Within later iterations we could also build new reference models especially for describing cases where bugs have appeared.

To test generation results we have to predefine what should be generated. For this purpose we should use one or two test models reflecting and covering all existing language concepts. Then we can use automatic diffs to ensure that the generated results are always equal to the predefined ones. This is the recommended way for testing generator cartridges.