Metaprogramming: Overview


Under this topic we are going to review a set of techniques, frameworks and tools commonly used for enhancing software development making it simpler and reusable. Metaprogramming is one of the most misunderstood concepts in software development, and it´s in fact difficult to be delimited. If we attend to “meta” prefix meaning from Greek we can think about “beside-programming”, “beyond-programming” and “after-programming”, this can be valid definitions, because “meta” prefix it´s also used for indicating an abstraction of another concept used for enhancing original one.

Traditional approach is about “a computer program that writes new computer programs” which is very similar to a compiler concept, but in this case the concept is much wider. Nevertheless, idea that code generation is embedded in application execution has a relevant weight as definition. Some additional definition about metaprogramming is about computer program that manipulated other programs at runtime. Others define metaprogramming as a set of programming techniques where code does more than just interpretation of computer language.

According to Wikipedia: “Metaprogramming is a programming technique in which computer programs have the ability to treat programs as their data. It means that a program can be designed to read, generate, analyse or transform other programs, and even modify itself while running

Here we are going to deal with this specific type of Metaprogramming which has to do with code generation through specific set of techniques and tools that will make our code simpler, readable and reusable. Along these set of articles we will mainly review the following techniques and tools:


As we will see in short, I´ll provide a specific set of articles for each of them, with their respective samples.


One of the main goals of metaprogramming is that you write less code. Less code less effort and usually more legibility. We can increase software cohesion and reduce software architecture coupling by implementing these techniques. Well known frameworks like ASP.NET MVC (CodeDOM), LINQ (Lambda Expressions), or even ORMs like Entity Framework (T4 Templates – Microsoft’s Text Template Transformation Toolkit) make explicit use of some of these tools. In the same way Static and Runtime AOPs like PostSharp exploits and provides metaprogramming capabilities.

Metaprogramming usually provides an orthogonal way for software extensibility by linking relevant information about how our system behaves with an ample range for customization. With metaprogramming we don´t strictly depend on language features for reducing code complexity or improving legibility, but we will use specific techniques and libraries for achieving these goals.

Is equally true that in order to implement some of these techniques a deeper understanding of the tools and extra effort is usually required. So some trade-off analysis is advisable.

Let´s start with the first topic : DLR (Dynamic Languaje Runtime)