There was a need to use a code generator. Presumably you will need to generate Java and / or C # code. I would like to generate it on the basis of UML diagrams + some templates in a simple language. Found quite a lot of different generators, which in a given volume solve the problem. To make it clearer, what you are talking about, you can look at the Agile Platform generator as an example. I ask those who used such generators to share their impressions. I suggest this format:

  1. The name of the generator.
  2. Ease of use.
  3. Save time (compared to writing code manually).
  4. Extensibility (first of all, it is of interest whether it is possible to generate code in its own languages ​​by describing their syntax).
  5. Brief description of impressions (in a nutshell!).

A big request not to turn into discussions like "code generation: is it good or bad?". Interested in the opinion of those who used the generators in practice, or at least in due time got acquainted with them. Thank.

    4 answers 4

    We have a codogen from java classes in c ++ and c # + the second java codogen in Java.

    Main thoughts

    • To write only by yourself, because the Kodogen requires a lot of support and small "ryushechek".
    • If you have a zoo of languages ​​and environments, the code is best based on a third-party descriptor, such as an xml file.
    • After 3 days, of course, everything will work for you basically ... But 3 more weeks will have to be spent to cover all exceptions :)
    • Kodogen is good! And the bigger the project, the bigger the good. On one of the past projects, we got a Kodogen when we had only three, and the code was no more than 30k lines. Even then he helped great.
    • Well, the rules are written in blood:
    • CODOGEN SHOULD BE DETERMINED. For the same files, the result should be the same up to a byte.
    • CODOGEN MUST BE 100% COVERED WITH TESTS.

      We have our own kodogenerator (not according to UML, but according to the DB scheme). If on to bother with CodeDOM (to make the generator independent of a programming language), it is written quite quickly. The stupid code generator according to the DB scheme is written somewhere half a day. Heaped up, with the ability to fine-tune the mapping (inheritance, enum, namespaces with different prefixes, redefining the properties of physical database objects) - three days.

        About ten years ago I took part in the creation of such a generator. The essence of the problem was this: there is a UML diagram of the processor bus test according to the specification, and it is necessary, through a series of transformations, to turn it into code in hardware description languages ​​(VHDL, Verilog, SystemC, etc.). This was done using Yacc / Bison and XSLT by several intern students during the month.

        Summary. It turned out to be easy to write a generator and the practical benefits were significant, but the support itself later (when the students left on other projects) was troublesome; so if there is an opportunity to buy ready, it is better to buy ready. The utility of the generator manifested itself when it was necessary to generate in several languages ​​at once, but if a test in one language was required, then there was no particular advantage over writing code.

        • And why Yacc / Bison? Do you have a UML in some text form? - Raider

        Here is a simple and unpretentious tool for generating UML code and building class diagrams from java code: java2uml .

          Protected by spirit community member ♦ Jan 20 '16 at 7.30pm .

          Thank you for your interest in this issue. Since he collected a large number of low-quality and spam responses, which had to be deleted, now it’s necessary to have 10 reputation points on the site (the bonus for account association is not counted ).

          Maybe you want to answer one of the unanswered questions ?