4 ms·
Avoid using metaprogramming (seriously)
- stcredzero 17y agoThe example in the article doesn't offer proof that meta-programming is bad. Rather, it is an example showing that you can sometimes implement something in a hacky, obfuscated way or in a clearer way. If meta-programming obfuscates your code, then don't do it! Do it when it clarifies your code. In fact: Does [X] obfuscate your code? Don't do it! Does [X] clarify your code? Do it! Doctor, it hurts when I do this! Don't do it! X can be unhelpful polymorphism, frivolous use of a pattern, ill-advised use of exceptions, or just about anything. Another thing to note: when meta-programming looks arcane, it's more likely to be obscure. When meta-programming looks more like ordinary programming, it's more likely to clarify. So a programming language that aims to be powerful should make meta-programming as casual as possible. Python and Ruby do this better than Java. Smalltalk does that better than Python and Ruby. Lisp does that better than all of the above.