views:

1105

answers:

6

In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo, T4 or CodeDom for generating code. Our goals are to keep dependencies to a minimum and drive code generation for a domain driven design from user stories. The first step will be to create the tests from the user stories, but we want the domain experts to be able to write their stories in a variety of different media (e.g. custom app, Word, etc.) and still generate the tests from the stories.

What I know so far:

  1. CodeDom requires .NET but can only output .NET class files (e.g. .cs, .vb). Level of difficulty is fairly high.
  2. T4 requires CodeDom and VS Standard+. Level of difficulty is fairly reasonable, especially with the T4 Toolbox.
  3. Oslo is very new. I have no idea of the dependencies, but I imagine you must be on at least .NET 3.5. I'm also not certain as to the code generation abilities or the complexity for adding new grammars. However, domain experts could probably write user stories in Intellipad quite easily. Also not sure about ease of converting stories in Word to an MGrammar.

What are your thoughts, experiences, etc. with any of the above tools. We want to stick with Microsoft or open source tools.

+4  A: 

Generally speaking I see code generation as part of a complete modeling/coding story. It should be accompanied by a generic framework in which most of the plumbing is done. In my opinion it is not useful to generate huge classes whereas a decent framework with well-defined extension points or hooks will be much better to maintain and to extend.

You will need to define some formalized language for the user stories, be it XML or an Oslo domain language. Oslo would require your domain experts to learn the Oslo tooling. You could use Word + XML. Then you define a good-looking template in Word, with an embedded XML schema and after the story is written you can get it from Word in formalized XML syntax.This XML can of course be used to drive generators, via XSLT or Linq.

CodeDOM is powerful, but rather cumbersome. It is IMHO not an easy to use solution and it does not have real template support.

I have no experience with T4, but its templating features are a pre.

The Oslo product is indeed quite new, requires .Net 4.0, a runtime environment. It is still only a CTP. It is a very powerful environment, although I have some doubts about the database generation story.

Hope this helps.

Rine
I would take a serious look at XML too :)
leppie
This is an excellent response and matches the overall approach I'm trying to take.
Ryan Riley
...template in Word, with an embedded XML schema... sounds interesting, any idea where I can find the info for further investigation? thanks...
bob
+9  A: 

Go with T4 - easy decision.

  • Oslo is too new and the tools are too raw to be anything than an eval-only technology
  • CodeDOM is powerfull, if you need to generate CLR classes at run-time, and are willing to sacrifice easy modification to your generated output.
  • T4 (with the T4 toolkit) is a easy to use general purpose code generation tool. Only difficulty I've had so far is in build-time integrations.
Scott Weinstein
This more directly answers my original question. Thanks for your input, Scott.
Ryan Riley
build time integration requires you to invoke the TextTemplate.exe file yourself, since VS.NET tends to lock any shared assemblies you use for reading in metadata. Once you've done that (from pre-post-build steps) it is really nice. I use powershell to do the file date comparisons to determine whether to invoke the templating engine.
Andrew Matthews
A: 

+1 to Scott Weinstien for bringing up T4.

For more on the topic, check out another Scott's excellent discussion with Kathleen Dollard at hanselminutes.com.

Alan
A: 

Well, Oslo does not fit the list. It has no code generation story so far. So stick with T4.

Lars Corneliussen
A: 

Oslo has not the intention to generate code for you. You will have to create a runtime (C# program for example) that changes it behavior depending on the data. You can see it like an internet browser.

I don't believe that Oslo requires a .Net 4.0, like Rine mentions. For my internship at Avanade Netherland I’m creating Oslo MSchema and MGrammars and a C#3.5 runtime. Depending on the given data it will creating (not generating) WCF services and run those.

A: 

There are some interesting application of Oslo

  • the "new LDAP" System.Identity, more in PDC session video http://microsoftpdc.com/Sessions/SVC28
  • System.Modelling (I think) Microsoft.UML2 where you can push informations about methods, classes, modules etc. in the Repository, analyze it and create reports. For example create report with methods added/removed between 2 buils http://microsoftpdc.com/Sessions/SVR19
  • and of course modelling
Karel Frajtak