When to use metaprogramming
Now that we know that metaprogramming has its own pros and cons, it is very important to learn about when to use it and how to decide whether you need it or not. The simplest answer to this question is almost never. In other words, before even considering metaprogramming, you should try to implement your solution without it. There are two advantages to this:
- You will most likely write a good, less complex solution that doesn’t rely on metaprogramming, and has low maintenance costs.
- You will write an almost complete solution that will exist independent of any metaprogrammed code. This also sets you up to decouple your interface (the metaprogrammed code) from your implementation (the non-metaprogrammed code).
Here are some other points for you to consider when considering metaprogramming. Use metaprogramming in the following situations:
- When you have exhausted all the other options. As mentioned previously, metaprogramming...