I think the most important thing to keep in mind is: WHY do you want to generate the source code. This, for example, is because you are more fluent in UML than any programming language, and therefore want to generate object-oriented classes from this graphical model?
Is it because you specified a schema definition in any language ( SQL DDL , for example: jOOQ , XSD , for example JAXB code generation ) and want to generate a model from this?
The advantage of code generation is always that you express something only once (as in DRY , as pointed out by Stephan ). This is a very good practice, which is deeply immersed in extreme programming (among other processes). When you hold DRY things, you do not risk that the model is different from the glue code. On the other hand, you can explode your glue code because it will exactly match its base model. Typically, you have one class / type / object for an RDMBS table or for an XML element.
If, however, you use code generation because it is more convenient for you to use a modeling language (as in MDA or model architecture ), you may run the risk that the generated code is not good enough (lack of details) or too complicated (lack of simplicity), because which, for example, UML is not suitable for detailed problem solving.
In any case: code generation can be very useful if the generated code can be used by AS-IS and does not need to be configured. Once you start customizing the generated code, it can become a nightmare for maintenance.
source share