Lightweight code Generation Scenario selection

Source: Internet
Author: User
Tags static class advantage

The last time we talked about Myappfuse to have a code generation tool, codegeneration.net a variety of platforms to bring together various language tools.

Some of the metadata used in UML became the most popular MDA tool of the last year. MDA is actually super rehash, even n years ago the graduation thesis is this topic, and now see progress is not big.

But it's normal to think of it. Because MDA is composed of model, implementation and conversion program, if the model definition has developed rapidly, there will be a huge gap between the underlying implementation and the need for the conversion program to do a lot of work to eliminate. When the gap is large enough, very few people will be willing to do this conversion work. And in order to reduce the gap, one is the development of the underlying implementation, but this is the entire IT industry, not the MDA developer's personal problem. The only way to reduce the height of the model definition, such as ANDROMDA, is that many out-of-the-box templates rely on UML static class diagrams and use a lot of tagged Value, which looks like a custom model in XML format.

So, one by the bottom of the constraints, and the OMG structure is not like a very high production organization, MDA suddenly erupted, we wash feet on the field no longer coding chance. But with aop,meta-data,o/r MAPPING,IOC container These low-level developments, as well as the impact of Microsoft DSL on UML, MDA will continue to develop slowly, after all, this is our dream.

It is more practical to choose some lightweight code generation schemes now. I picked a custom model in XML format + jsp/freemarker template. Of course you can use xdoclet like Appfuse, but I think Xdoclet's scalability, management and scope of application are the lowest. You can also use the C#/java program to completely control the generation of the code without using a template, and now you have more python,ruby these dynamic languages to choose from.

But I'm still a little more accustomed to templates. For example, JSP, you can use httpclient access JSP, get the return content to generate files. XML-formatted metadata can be put into the request or session via filter.

However, velocity and Freemarker are now popular. Between the two can be a three-inning win system.

One, there is an article on the Freemarker website that lists the advantages of freemarker syntax over velocity.

Second, but now the PM can not be so narrow from a purely technical point of view, Velocity has a much more than freemarker user groups, such as ANDROMDA, IntelliJ idea.

Third, and yet, for this metadata defined in XML format, Freemarker has a rarely mentioned but no advantage--built-in access syntax for XML DOM. For example, the following meta data:

<table>
<column name="id"/>
<column name="name"/>
</table>
Freemarker可以这样列出table下所有column的name:
<#list table.* as column>
${column.@name}

Comparing velocity to using the Jdom API, it's easy to know how many times. On this, let Freemarker win, because the code generate process, really want to access too much XML metadata. Also this, let me in JSP and freemarker between ambiguous. Originally, because the generation is the code, not the page, Freemarker markup-language Advantage does not exist. And the advantage of JSP is that everyone knows, and have the best IDE, extensibility is also super strong, can do arbitrary things.

However, in the final analysis, what to do with the template, in fact, is not a very important thing, here is just write group memoring, record low decision process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.