...

/

The Power and Perils of Metaprogramming

The Power and Perils of Metaprogramming

Let's discuss the two flavors of metaprogramming, as well as a few metaprogramming risks and the keys to overcome them.

Metaprogramming is writing code that writes code. When using a third-party class, if you’ve ever said, “It would be really great to have this particular method in the class at hand,” you can use metaprogramming to make that wish come true.

Metaprogramming is not practically approachable for most developers unless the language lends itself for extension using hygienic syntax native to the language. In general, dynamically typed languages, due to their ability to dispatch method calls without rigorous type verification, offer better metaprogramming facilities than statically typed languages.

Just because a language is dynamically typed, however, does not make it automatically suitable for metaprogramming. The language also has to offer specific tools. A good example of this is JavaScript. Even though the language has been dynamically typed from its inception, until recently, it lacked the necessary tools to do full-fledged metaprogramming.

Injection vs synthesis

Metaprogramming comes in two flavors:

...
Access this course and 1400+ top-rated courses and projects.