By Peter Bell

Old Skool Code Generation

As you know, I tend not to love using databased metadata for generating code or XSLT for templating as one is limiting and the other is (to me) a little obtuse. That said, Brian Rinaldi has just posted a great article on how he wrote the Illudium PU-36 Code Generator over at Fusion Authority.

It runs you through the whole process and I think is a must read for anyone playing with code generation.

To clarify my position, I find XSLT a little inelegant and thus prefer CF Template which is more powerful and concise, but outside (and inside) of the CF world XSLT is widely used, so it is a very valid approach.

As for databased metadata, the problem is that because it only knows basic information (it knows that a field is a varchar(8) but doesn't know it is a US Social Security Number - for example), the generated code acts only as scaffolding - a starting point for customizing the code base.

That said, unless you've written your own object based code generator, a starting point is better than nothing and playing with something like Illudium would make writing a more robust generator easier.

Well worth checking out.

Comments
"Ya see that? That's the way to do it. That's old school."<br/>
"Yeah. No school like the old school."

However, while I am in agreement that there are limits to db introspection for code generation, I am not sure I would call it "old skool." It does offer an very easy way to get some basic code generated...as in the barriers to entry are much lower than setting up your metabase and it can be an invaluable time saver.
# Posted By Brian Rinaldi | 1/11/07 8:57 PM
Agreed. It is a great way to get a jump start on an application.
# Posted By Peter Bell | 1/12/07 1:37 AM
Why would you consider XSLT an inelegant solution?? What would be its pro's and con's in comparison to CF Template????
# Posted By Luis Majano | 1/12/07 5:33 PM
By the way, I would be careful on leaving the send feature without a captcha. I had tons of spiders and bots sending email out through it.
# Posted By Luis Majano | 1/12/07 5:34 PM
Hi Luis,

Inelegant just in terms of signal to noise (do you SEE how long variables are in XSLT) and the fact you can't put angle brackets into your generated scripts. Imagine using XSLT instead of ColdFusion for doing all of your HTML templating - it'd drive you crazy. I want my generation templates to be easy as my HTML templates generated by CF in terms of readability and efficiency, so that is why I prefer CF Template.

Also CF Template provides me with all of the functions in ColdFusion so if I want to handle number formatting ro date formattng or something in a template I can use CF for that rather than having to figure that out using XSLT.
# Posted By Peter Bell | 1/13/07 5:56 AM
Hi Luis,

What do you mean "leaving the send feature without a captcha"? I have a captcha in the comment form. Is there something I'm missing?!
# Posted By Peter Bell | 1/13/07 5:57 AM
If anyone is trying to use Brian R's code generator with MySQL 4.1, I have re-written the database introspection portion so that it will work. Currently the only MySQL version it works with is version 5. Email me if you want the code.

It has saved me so much time typing out my beans and DAO's! It is indeed a great place to start with OOP. Thanks Brian.
# Posted By Josh Nathanson | 1/15/07 5:58 PM
Whoops sorry, my email address is josh (at) igigi (dot) com.
# Posted By Josh Nathanson | 1/15/07 5:59 PM
Thanks Josh. I still plan on integrating your code into the official release...just time hasn't allowed yet. Thanks for the compliments though :)
# Posted By Brian Rinaldi | 1/15/07 10:18 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.