Design Patterns as External DSLs

I’ve been thinking about how you might layer DSLs into ever increasing abstractions and how you might combine multiple DSLs with ease. These are problems I definitely don’t have the answers to just yet but while looking at how Axum is coming along I can’t help but feel like Axum is a language designed specifically to help you write code that conforms to a specific design pattern. I mean it’s still .net under the hood (I think) which is no more or less async safe than what you or I can write manually but it constrains you such that you cannot create bad asynchronous code (or should make it much harder at least!).

This is really fascinating to me, since intuitively it feels like a really good idea but I don’t quite get how it can coexist with other types of development or DSLs right off the bat. I also think it reinforces the idea that constraint, at times, can be more powerful than flexibility. One of the things about “dynamic” languages that I’m not totally convinced about is the how it feels like the wild-wild-west, anything goes type of programming. Sometimes having limiting constructs can actually more powerful and that is not appreciated enough, I don’t think.

Anyway, I was just trying to picture a world where you had one DSL where you designed various models for your application and another DSL where consumed them in a specific design pattern. This seems feasible I’m still trying to figure out how you might “glue” them together. Probably using templates somehow. Food for thought, if anyone has any insight or ideas leave a comment!

DSL DevCon 2009 Videos

The videos for the presentations at DSL DevCon 2009 are now online. You have to scroll down a ways to get to them but here is the link:

http://msdn.microsoft.com/en-us/oslo/videos.aspx

If you don’t have time to watch all of these then at least check out the video that everyone is talking about from the Intentional Software team:

http://msdn.microsoft.com/en-us/oslo/dd727740.aspx

enjoy!

Out with Code Generation and in with Transformation

As I’ve been playing around with DSLs for the past couple of years I’ve been focused on Code Generation as my primary strategy. This is all well and good and I think that code generation still servers its purpose in the greater world of DSLs but it’s not quite good enough. I would like to start using the word Transformation as more generalized form of code generation and manipulation. What I used to refer to as Code Generation I will now simply call Textual Transformation. The other main form of Transformation is an AST Transformation. The Groovy folks have also adopted this to be synonymous with Compile-time Meta Programming and the Boo folks would call this a Syntactic Macro.

In order to promote the DRY principle and really allow N levels of arbitrary transformations I’ve been busy changing MetaSharp to adopt the Pipelinepattern for the compilation process (according to that wikipedia article what I have now is more of a psued-pipeline though, since each step is done synchronously). The end result is pretty simple actually.

image

The Pipeline has a series of steps and a collection of services. Each step depends on certain services and may alter / create certain services. In this way each step can be completely re-usable for different compilation scenarios. For example the MetaCompilePipeline has three steps:

  1. MetaSharpCompileStep
  2. CodeDomTransformStep
  3. CodeDomCodeGenerateStep

Which is to say, if you want to compile MetaSharp code inside of a project of a different language your pipeline needs to perform those three steps. First compile the code into MetaSharp AST nodes. Second transform those nodes into CodeDom objects. Third use a CodeDomProvider to generate code based on those CodeDom objects. The MetaTemplatePipeline is the same as the above with one extra step at the beginning, for transforming the code into something else.

The point here though, is that key to this whole process is the idea of Transformation. In fact the whole theory behind MetaSharp is simply to be a transformation tool. Each step is simply transforming the results of the previous step into something else. This is powerful because your DSL can consist of arbitrary levels of transformation, litterally your DSL could transform into a lower level DSL, which transforms into an even lower level DSL, etc. all the way down to machine code.

Transformation isn’t a new concept it’s, been around forever. At the very root of any software is essentially a bunch of 1’s and 0’s but we haven’t written raw 1’s and 0’s as our software for a long time. The compiler has always been a way for us to transform slightly more complex concepts into lower level ones. Even the extremely low level machine code is a step above raw 1’s and 0’s. General purpose programming languages themselves consist of constructs used to transform into much more verbose machine code or IL.

Taking transformation to the next level of abstraction is necessary for us to effectively create DSLs. If there was a tool to help us easily perform those transformations then it would go a long way towards making external DSL authoring more realistic, which is what I’m hoping to do with MetaSharp.

So to me, at this point, Code Generation is just another form of Transformation, which I will be calling “Textual Transformation” from now on. It has its pros and cons, of which I hope to discuss further in other posts. However, my point today is simply to convey the idea of Transformation as more general and more important to the DSL world than simply Code Generation and also to consciously force myself to update my lexicon.

Axum – A DSL for parallelism

There is an interesting new language called Axum, which appears to be very much a DSL from my perspective, that focuses primarily on parallelism.

Axum, previously known as Maestro, is a Microsoft incubation language project meant to provide a parallel programming model for .NET through isolation, actors and message passing. The language borrows many concepts from Erlang but with a C#-like syntax.

Axum is an imperative language with a C#-like syntax. While it is aware of objects, classes cannot be defined, because the language is domain and actor-oriented instead of being object-oriented. Axum is not a general purpose language being targeted at solving concurrency tasks and is built upon Concurrency and Coordination Runtime (CCR) from Microsoft Robotics.

It’s really interesting to think about when you realize that parallelism is in fact a solvable problem from within a general purpose programming language. However the problem is so complex that it is generally very difficult for anyone to get it right (with object oriented languages at least). So their solution was to create a DSL that doesn’t let you get it wrong (or minimizes it at least). I think this is the perfect example of why an external DSL can be so powerful.

External DSLs can allow you to model, what would be a complex design pattern in a general purpose language, with much lower rate of errors. You couldn’t do this nearly as effectively in an internal DSL.

More from the Axum team: http://blogs.msdn.com/maestroteam/archive/2009/04/17/forging-ahead.aspx

SmallBasic at the Twin Cities Languages User Group

The next meeting of the TCLUG will be on the language Small Basic, presented by Jeff Klawiter. If you have an interest in learning a new language or have children that might be interested in getting into programming you should come to this presentation (and bring the kids)!

Oh yeah, and free pizza.

http://www.twincitieslanguagesusergroup.com/TCLUG/Events.aspx