Metaprogramming is writing programs that operate on other programs. So writing:
is metaprogramming. But the fun kind of metaprogramming is writing a program operates on itself.
If a program simply looks at and reports on itself, we call this introspection. If the program also modifies itself, we call this reflection.
Here are questions you can ask, and things you can do, that fall under the umbrella of metaprogramming:
Here are some examples in no particular order.
Python has good metaprogramming support.
Ruby just may win for the most metaprogramming-friendly and metaprogramming-rich language of them all. There are entire multi-week courses and whole books devoted to Ruby metaprogramming.
eval and an interesting constructor for
Function. It has a cool
You might think that Java, because it is so static and so verbose, couldn’t have too many metaprogramming features. But that is so not the case. It has annotations. It has a reflection package. It has a lot more.
Go doesn’t really have the same kind of metaprogramming facilities you see in other dyanmic languages. It has some support for reflection via
As a language in the Lisp family, Clojure’s metaprogramming facilities are strong.
Julia features Lisp-like (and Clojure-like) macros, built from abstract syntax trees rather than source code text.
Looking for some fun? Write some quines.