cf.Objective() Session - Leveraging Code Generation by Brian Kotek

Posted on May 02, 2008

I am here scoping out a topic near and dear to my heart, code generation (also to make sure Brian doesn't forget Illudium ;). Thankfully he did not forget.Brian noted some of the benefits of code generation, including that it is easy, fast and provides some consistency. There are two kinds of code generation, passive generation which is generally one-way and one-time (like Illudium). Obviously once you have modified the generated code, the generator isn't useful to regenerate code. Active code generators include round-trip code generation that allow you to regenerate code when the metadata changes. This is ideal but is very difficult to achieve. Some issues to keep in mind are understanding the generated code, not customizing or refining the generated code or allowing the database to dictate your object model.

CFEclipse Snippets
Snippets generate reusable blocks of code and have templates with variable replacement. They are extremely easy to use and can be shared via SnipEx libraries. You can even tie them to "trigger text" to have a shortcut for creating commonly used snippets. Brian showed some very useful snippets he used to create getters/setters, application.cfc and a basic XHTML template.

Apache ANT
Apache ANT can generate anything using templates with variables that get replaced. You can use it within Eclipse or from the command line. Cairngen uses this method to generate Cairngorm code and Brian shows a demo of this.

ColdSpring
ColdSpring will generate proxy CFCs. It generates via templates that are revised via variable replacement. Remote proxies are generated and written to disk. This is useful for making methods available as remote for Flex or Ajax. Using ColdSpring's AOP (aspect oriented programming) is also essentially a method of code generation but the generated file is written to disk and immediately deleted in this case.

Reactor ORM
Reactor uses XSL and database metadata which are generated according to configuration files to generate CFCs that are written at runtime and overwritten as needed. It also generates customizable components that extend the generated CFC. These files can be modified without fear of being overwritten. In this manner Reactor would qualify as an active generator.

Transfer ORM
Transfer writes definition files to disk based upon the configuration and injects them at runtime. You can add custom code into decorators which will not be overwritten.

Scaffolding
Scaffolding will create CRUD for rapid prototyping but is generally not good for production code. Model-Glue Unity and Fusebox 5.5 both support scaffolding.

Illudium PU-36
Finally! Brian K. says it is the "most popular generator in the ColdFusion community." Case closed. :)

CFC Stub Generator
This generator created by Brian Kotek generates stubs for CFCs, unit tests, ColdSpring config and tests suites. Is based upon UML. Everything within the UML diagram is stubbed out in CFCs with unit testing.

Comments

There are currently no comments for this entry...be the first!

Write your comment



(it will not be displayed)





About

My name is Brian Rinaldi and I am the Web Community Manager for Flash Platform at Adobe. I am a regular blogger, speaker and author. I also founded RIA Unleashed conference in Boston. The views expressed on this site are my own & not those of my employer.