Thursday, Aug 11, 2005, 4:05 PM in Tools
What should I do w/ the metadata?
Imagine I've got some "metadata" that describes some functionality of my system, e.g. the command line parameters to a tool:
<args description="Two wrongs don't make a right, but three lefts do">
<arg name="lefts" description="Number of left turns" type="int" default=4" />
<arg name="attitude" description="Driver attitude" required="true" type="string" />
</args>
Once I have this "metadata" in place, should I a) use it to generate a class at compile-time that implements the command line parsing, or should I b) use it to drive a command-line parsing framework at run-time?
If I do a), generate the code, the result might look like this:
class Args {
public void Parse(string[] args) {...}
public string Usage { get {...} }
public int Lefts { get {...} set {...} }
public string Attitude { get {...} set {...} }
}
I've got better perf, but I have to generate the code in some way and .NET doesn't come with any built-in tools to do that (no, I don't count ASP.NET or XSLT as good codegen tools). Plus, the command-line args are now baked in and require a re-compile to change and who cares about perf to parse the command line? Finally, I'm much more likely to have most of the work done in a base class, e.g.
class Args : ArgsBase {
public void Parse(string[] args) { return base.Parse(args, ...); }
public string Usage { get {...} }
public int Lefts { get {...} set {...} }
public string Attitude { get {...} set {...} }
}
In my experience, most of the work of code-gen is generating the smallest possible bit of code to provide a nice wrapper around a base class that does most of the work in a very interpretive manner.
If I do b), have a run-time interpretter of the "metadata," I've got to build a command-line argument interpreter, but, as I've said, you almost always have that anyway. However, I also give up a develop-time wrapper aka "Intellicrack" which will be pried from my cold, dead fingers.
What do you guys do?