Skip to content

Tag: EMF

Code Generation is Not Agile

I am a great advocate of software modeling, which provides a higher abstraction of software artifacts that allow us easier work with them. For my current project (OPM Editor and Interpreter) I use a model based on the eclipse modeling framework (EMF). Until now I had only a model for the editor, and when I started to implement the interpreter the names of the packages that I set for the editor model didn’t seem good enough, so I decided to refactor them. Oh what a headache. I changed the name of the package in the genmodel file and regenerated everything… but now I have to manually update and remove all the old files, trying to remember which files has manual changes (with @generated NOT annotations).

What is the problem here? that the current MDE methodologies (Model Driven Engineering) or any of its names (MDA, MDD…) support mostly forward transformations (from model to code) but if the code is modified the model does know this. Furthermore, the model is not aware of the code, and like in my case this can create duplicate files (if you changed the name of the package for example) and other strange stuff.

So take this into account when you are using model driven methodologies and code generation. At my previous job we NEVER mixed manual code with mixed code, so changes to the generated code did not alter the manual code, and we could always plug the manual code into any generated code changes (with manual hooks). This is a good practice that should be followed. And if you don’t know if your generated code can be refactored, spend more time thinking on how you will name things, because they will be hard (and expensive) to change later.

Enhanced by Zemanta