3 ms·
Metaprogramming is a sharp, sharp tool that many people are liable to cut themselves with - it does lead to hard-to-understand and hard-to-debug code, so you ha
by akeefer 18y ago
Metaprogramming is a sharp, sharp tool that many people are liable to cut themselves with - it does lead to hard-to-understand and hard-to-debug code, so you have to make sure the tradeoff is worth it. As with any such tool, you just need to use it with restraint.
I've personally come to the conclusion that without metaprogramming you really can't write decent frameworks; even Java frameworks tend to use reflection and even run-time code generation, and I think the lack of more capable metaprogramming abilities in Java is one reason frameworks in Ruby, Python, etc. are more user-friendly. Frameworks are crucial these days, so I think metaprogramming is also essential to a language. It's just something that ideally would be used only in cases, like frameworks, where only a few people have to actually understand and debug it and a large number of people can leverage that work.