CodeDOM

Adding .net code execution wasn’t even 1% as painful as I was fearing it to be. I suspect this is how the more established player(s) carry out code generation: codesmith,mygeneration, even this fellow; and then they built upon this approach.

Using dot net code (or T4) has some pros and cons.
Pros:

  1. Low learning curve with using an existing language syntax.
  2. A very much shorter implementation time because a language base is already there (codeDOM implementation took me only a few days total).
  3. Integration with existing libraries, leveraging more power, saving more time.

Cons:

  1. Extra dependencies such as the framework or run-time.
  2. In my honest opinion imperative, object oriented, procedural languages are a little cumbersome for use with this type of code generation. The resulting template code ends up performing some gymnastics and becomes difficult to read. And annotations galore!

I think the complexity and readability issue weighed the heaviest for me. From my experience the intricacy and power of established langues is best hidden from the “main meat” of code generation. The Metadrone syntax is intended to be very lean. There’s no real need for object orientation, type safety, inheritance, overloading, etc. It’s the old 80/20 rule. 80% would be basic looping through model entities – which currently are database tables and columns – but 20% may require some clever thinking which is where using a mature and sophisticated programming language would be useful. Rather than expand upon the Metadrone syntax, which will just make life harder for myself in development effort and for the end user in learning new syntax, Metadrone can just pass information into managed code and get the result back.

To define the managed code you can add code items as you would a template. You can either add a VB or a C# code “file”. You can add as many as you want. The parser will just join them all together appropriately (all the VB code and C# code separately) and use the codeDOM library to compile the code. Instantiating and invoking is performed with the new function “runvb” or “runcs”.

For example if you had some C# code:

public class CS    {
        public string Blah(string blah)
       {
            return blah + " blah";
        }
}

within Metadrone you can invoke it:

<<!for table tbl in MainConn!>>
<<!for column col in tbl!>>
<<!tbl!>> - <<!runcs("CS.Blah(""some text""" + col + ")")!>>
<<!end!>>
<<!end!>>

I intend to make Metadrone objects properly accessible within managed code. Therefore if you wanted, you could just use plain codeDOM instead of the template language. The flexibility will be there depending on need and preference.

 

About Steve
Steve is the developer of Metadrone.