I haven’t quite made it out of Slovenia yet. To be honest: I’m not sure I want to. I like it here! Yesterday was a glorious day and the hike from Trento Valley up to Vsice and down to Tamarju hut via Grol was awesome. On the map it looks like a second-class hut, isolated, but surrounded by fields. It’s not!
Looking down on Tamarju Hut from Grol. Over the edge is one hell of a scree descent!
The hut was very busy which implies it’s a sociable place. I can’t be having that! So I walked out towards Ratece and stayed at the first quiet place I found.
Hiking is one of my favorite passtimes. My other is shrouded in geekiness: programming. When I get some time between hikes I am working on a code generation infrastructure. I have been using code generation for about four years but the entire infrastructure and generation process was hand-crafted because I could not find third party tools do what I wanted. The DSL Tools are now at the point where they either do what I need or can be moulded to do what I need.
I am trying to take everything I have learnt and put them into an infrastructure for generating my classes using the DSL Toolkit and T4 in Visual Studio 2008. I figured I will always need classes so I should be able to use this as a foundation for wherever I end up writing code in future [I had been working with this on and off for months before I started blogging; any new technical issues I encounter I will try to blog about]. I really wanted to do this with VS2010 Beta 1 but it is currently a bit slow.
So here’s my Class DSL so far:
A small part of the Canon SDK modeled using my DSL Class Editor
It looks like very little but the technical issues have been solved (those that work with DSL and VS2008 will know how fun this is to do!): the diagram has been rehosted in a custom control; the repository consists of numerous models (which I will replace with the “Model Bus” in VS2010, I guess), cross-referencing and cascading deletes/renames works across models and so forth. It’s just the user interface that’s tat. I loathe UI work!
So if it seems I am spending a long time getting across the Alps it’s because I am living my ideal life at the moment. I get to spend all day outdoors getting soaking wet in the regular downpours and scared sh*tless by the daily thunder storms, and the rest of the time coding away on stuff like this. If I find somewhere I like I stay there for a few days. Switzerland is my target but I think my ego will cope if I don’t quite make it that far! I am in the fortunate position of being in no hurry to get anywhere at all
One of the problems I have with the current DSL Tools is that it’s difficult to separate the domain model (what) from the code that you generate (how). Take for example the Class diagram above. I would argue that whether an attribute – such as OwnerName – is ReadOnly or Calculated is a property of the generation process and not of the DSL itself. For example: if I was generating that code for firmware in C++ it would need to be read/write. If I was generating the code for a UI/Web-presentation it would only need to be ReadOnly.
It always seemed a bit strange to me that having adopted modeling to raise the level of abstraction you were forced to tightly couple how you wanted to use the model with the model itself. Unfortunately, there is currently no way to easily separate the two so I am having to roll my own using a mish-mash of TypeDescriptor and PropertyDescriptor (yes: those beasts!) and extension methods. That way, the model and the code generation parameters appear in the same Property Grid and provide a cohesive environment for the user even though they are persisted in different files.
The stuff in the red box should not be part of the DSL.
I got the whole idea for this approach from this article on using Extension Methods in T4 by GarethJ some time ago.
I am happy to roll my own at the moment but when I migrate to VS2010 I am hoping it will provide the infrastructure that I can build on: namely, DSL Extensions. I haven’t investigated them at all yet but I am thinking that decoupling code generation parameters from the underlying DSL (by simply “extending it”) is one of the things they can be used for. I could be wrong: I’ve no idea yet!
Adios!