Most constructs / schemes in programming serve an essential purpose (sometimes more than one), for instance :
- Structs in essentially C's solution to the problem of providing user defined data types.
- Classes in C, Python, generalize the concept and allow for OO programming.
- Templates or type parameters or generics (C++, Java, etc.) allow for the type of a variable to be passed as a parameter, and thus makes it possible to write more generic code by abstracting the actual type of a variable away (in an algorithm, for instance).
- etc.
So I assume that "macros" also serve an essential purpose. I understand that it gravitates basically about "meta-programming", but what is the concrete advantage expected from it? What potential problem does it solve in main cases?
Based on the examples above, if you had to summarize the idea in one short sentence, how would you formulate it?
In particular, I am wondering what the point of being able to define dynamically the name of a function (for instance) could be?
Somehow, the abstract idea of macro seems to be at the top of the following hierarchy of abstractions (or generalizations):
the concept of parameter of a function.
The concept of the type of a parameter bieng itself a parameter (generics, templates, parametric types).
The concept of a function being passed as a parameter to another function or a function returning a function.
Etc.