Monday, October 15, 2007

Metaprogramming Approaches compared

I was recently thinking about different approaches of meta programming. Specifically, I was comparing the approach taken by converge, and the one taken by Ruby. Of course, the primary difference is that Converge is compile-time, whereas Ruby is runtime meta programming. But there's another difference:

In Converge,
the process works as follows: the parser reads your DSL-specific code into a parse tree based on a custom grammar. Then you as the meta programmer get a chance to process that parse tree - and what you'll typically do is to transform it into a regular converge AST. To make that simple, Converge provides macro facilities.

In Ruby things work completely differently. You (mis)use all kinds of more or less obvious language features to somehow make your own DSL be valid Ruby code. As a consequence, the meta program often looks awkward, it is not easily understandable what happens. Also, you cannot use *any* syntax you want - because it has to be valid Ruby syntax.

I really think the approach taken by Converge is cleaner - since you have one clear transformation step, as opposed to using all kinds of eval, block and other trickery. It would be interesing to use it in a dynamic environment.

Any opinions?
I don't know Converge, but one of the benefits of sticking with an internal DSL is that I can "escape" to the host language anytime my DSL isn't powerful (or convenient) enough. It's also extremely easy to create a DSL using this approach.

Just my 0.02€ ...
I agree that symbolic integration with the host language and escaping into the host language are important for internal DSLs.

But you could still to that with a Converge-like approach in a dynamic language. All you would to is intercept the stage between what the parser reads from the text file and the interpreter actually doing something with this parse tree.

converge sounds a lot like Intentional's Tree representation and the ability to define transformations on it. Surely the cleaner solution and quite similar to stepwise refinement by model transformation (from the graphical model viewpoint).
I agree that it is close to the model-to-model transformation appraoch when working with external DSLs (graphical or not).

But it is not very related to the intentional approach. In intentional programming, you start from a tree and project the visual representation. There's no parsing involved, and the tree is not a parse tree.

Markus is quite right that there's a fairly fundamental difference here between Converge and the Intentional stuff. Simplifying a bit I would say the following. Intentional have a sort of "universal" tree representation that they can automatically translate between; it seems reasonable to assume there are practical limits to what languages can be translated into and out of this. Converge allows pretty much anything to be translated into its internal form, but there's no automatic way to translate from DSL A to DSL b.

Both approaches therefore have advantages and disadvantages. As they both evolve, it will be interesting to see when one or the other is more suitable.

Post a Comment

<< Home

back to

This is Markus Voelter's Blog. It is not intended as a replacement for my regular web site, but rather as a companion that contains ideas, thoughts and loose ends.

December 2005 / January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / July 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / May 2008 / June 2008 / July 2008 / August 2008 / September 2008 / October 2008 / November 2008 / December 2008 / January 2009 / February 2009 / March 2009 / April 2009 / May 2009 / June 2009 / July 2009 / August 2009 / September 2009 / October 2009 / November 2009 / December 2009 / January 2010 / February 2010 / April 2010 / May 2010 / June 2010 / July 2010 / August 2010 / September 2010 / October 2010 / November 2010 / December 2010 / January 2011 / March 2011 / April 2011 / May 2011 / June 2011 / July 2011 / October 2011 / November 2011 / December 2011 / January 2012 / February 2012 / October 2012 / January 2013 /

You can get an atom feed for this blog.