Search code examples
metaprogramming

Are there real world applications that use metaprogramming?


We all know that MetaProgramming is a Concept of Code == Data (or programs that write programs).

But are there any applications that use it & what are the advantages of using it?

This Question can be closed but i didnt see any related questions.


Solution

  • IDEs are full with metaprogramming:

    • code completion
    • code generation
    • automated refactoring

    Metaprogramming is often used to work around the limitations of Java:

    • code generation to work around the verbosity (e.g. getter/setter)
    • code generation to work around the complexity (e.g. generating Swing code from a WYSIWIG editor)
    • compile time/load time/runtime bytecode rewriting to work around missing features (AOP, Kilim)
    • generating code based on annotations (Hibernate)

    Frameworks are another example:

    • generating Models, Views, Controllers, Helpers, Testsuites in Ruby on Rails
    • generating Generators in Ruby on Rails (metacircular metaprogramming FTW!)

    In Ruby, you pretty much cannot do anything without metaprogramming. Even simply defining a method is actually running code that generates code.

    Even if you just have a simple shell script that sets up your basic project structure, that is metaprogramming.