What is the difference between metaprogramming and reflection?

2

There are two terms that look a lot like when we are talking about introspection techniques. They are and reflection

Wikipedia treats reflection as a key strategy of metaprogramming but for me these terms are identical or I do not know what sets them apart.

What is the difference between terms? Is there reflection without metaprogramming or vice versa?

    
asked by anonymous 13.02.2018 / 22:05

1 answer

3

I disagree with the Wikipedia definition. The metaprogramming text seems to be a little better.

Reflection is a mechanism that gives information about the code itself and allows you to modify it. This can occur at runtime or compile time, what matters is access to information to manipulate it (if you do not manipulate it just introspection ). It is only more common to occur at runtime.

Metaprogramming is a > Paradigm that allows you to manipulate the code more generally, you program how the code should be programmed. Reflection is often used to get the information you need and change what you need, but it is not the only way. And it is more common to occur at compile time.

There are other mechanisms that provide the same ability of the code to be aware of itself. One of them is the use of a meta language or extensible language . But it can only be generics or templates .

The paradigm is pushing the outsiders and mainstream languages are increasingly approaching it. But beware, it's too hard to use it right, so it's always been avoided, even though it's been around for 60 years.

Of course in each context the definition may vary slightly. In more academic environment will be more widespread, in some communities will pull the sardine pro side of how it uses. There are those who disagree that what mainstream languages such as Java and C # have in fact reflection, at most have a library that helps in a piece of code, ie JEE or .NET that is thoughtful.

    
13.02.2018 / 22:49