[Tech-Ed] BOF - Code Generation
Scott Hanselman lead a BOF on Code Generation. I agree with Andres - there was a lot of discussion on business rules definition, which was interesting but I think took away from more common uses of codegen.
Peter Provost was talking about using the Code DOM to crank out one off's. Peter's a lot smarter than me, and can probably burn the extra brain cycles on the Code DOM complexities. Seems like a lot of work to me.
Others talked about using XML and XSLT to write their code for them. I agree with the sentiment others expressed - XSLT is not an easy language to program in. Programming logic into XLST is like writing procedural cursor based T-SQL - you can do it, but it'll make you cranky and you won't understand how it works in three months. I like the declarative model in concept, but the XSLT work I've done has been tedious at best.
John Lam talked about the "angle bracket tax" of XML, but he was advocating what basically amounted to writing your own language. I don't know about that - codegen's supposed to create less work, right? Once again, I guess if you've got some cycles to burn then go for it, but I'm looking for solutions that simplify my work. I'd rather not have to debug my custom code generation language while I'm trying to complete a project.
So, to sum it up... people were talking madness and I felt like I was taking crazy pills.
Then in the last 10 minutes, Scott presented what he's doing. He's using CodeSmith. I use CodeSmith. I love CodeSmith. CodeSmith is easy - it's ASPX code, which I know. It's powerful. It's easy. It seemed they were pumping sanity back into the room through the ventilation system.
Scott pointed out the difference between generating code based on nouns (domain information) vs. verbs (business rules). He said you should start with what's easy to describe - the nouns. Agree. Describing nouns is easy, so it's easy to automate. Describing business rules (e.g. tax code) is not easy. As Scott said, starting with CodeSmith's Strongly Typed Collection Classes is a good way to get a quick win with codegen.
Scott's company uses XML Schema to define entities. The elements have domain specific attributes. They've extended things quite a bit - for instance, the properties have custom attributes which describe formats. The data is isomorphic. That's good, I think.
They's then gone on to describing the business rules using WSDL. Purty slick. They map multiple inputs (database, mainframe, etc.) to multiple outputs (web, wap, client) through a generated framework. Cool.
We've been using CodeSmith quite a bit at my work - I've been meaning to blog about some of the things we've come up with (extending codegen code with support for regen, custom filtering, etc.). I'm sure it's all been done before, but might save someone some time.
So, I enjoyed the session. I wish Andres had spoken up (I'll try to catch up with him at the DeKlarit booth this week), and I wish Scott had spent a little more time describing what he's doing. But, Scott ended the session by giving out copies of CodeSmith Pro so there's no way I can complain.