4 ms·
My analyst warned me, but metaprogramming was so beautiful I got another analyst
- icey 18y agoWhenever I read the argument that metaprogramming is terrible because it leads to hard-to-troubleshoot code; it leads me to believe that the person making the claim: a) works with terrible programmers and b) has no idea how to discern who the terrible programmers are.
- astrec 18y agoWhenever I read the argument... In my case, it's simply "Hark! The clarion call of the librarian". ;)
- Herring 18y agoYou hit the nail on the head. B is the real problem. There's nothing intrinsically bad about having billions of authors/programmers. But if you can't separate noise from signal, you start to think maybe a whitelist isn't such a bad idea.
- andreyf 18y agoWhat will happen if you include meta-programming in a language isn't as simple as "this will happen" versus "that will happen". A deciding factor is the structure and process in which your organization works. Structures which work well for creating Java code probably won't work well for creating JavaScript or Ruby code. A couple of things come to mind: 1) Code reviews are a lot more important for languages which allow 'meta-programming' 2) Thorough, but concise documentation, also. Extending Class.inherited() (as quoted in the linked article) without telling anyone or documenting it is a social problem of process and organization, not one with the programming language.
- DougBTX 18y agoI'm not sure you can excuse the language totally. To stop code standing on other peopoles toes, namespaces and encapsulation were invented. In this case, there is no way to encapsulate the change to Class.inherited, it must be Global, because the language does not support anything else. If the language did support other possiblities, then the social problems would have been less acute.
- mynameishere 18y agoSummary of argument: Your opposition to (whatever) is just like the old priestly order's opposition to the printing press.
- raganwald 18y agoYes, exactly, for the specific reason that Jeff didn't just say extending languages was terrible, he took several paragraphs to talk about how we the people are unqualified to do so compared to his personal list of exalted greats who have invented the languages he admired. So I felt the repsonse mirrored the original post.
- ph0rque 18y agoReverse Godwin's law?
- akeefer 18y agoMetaprogramming 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.
- gruseom 18y agoIsn't Atwood one of the types who get all indignant about the "Blub" argument? Maybe he should think twice before utterly confirming it.
- jrockway 18y agoThe good news is that Atwood's blog is targeted at Joe Average Code Monkey. He's probably right to tell his audience to ignore metaprogramming; if they are willing to do what he says, it's probably a good thing they're not trying to write good code. All they would do is break things horribly, and then complain about how badly powerful tools suck. His writing mostly exists to make the people writing PHP pages with SQL queries mixed in with <table> tags feel like they are good programmers. Whatever. For those of us that actually know how to use powerful tools without cutting off our fingers... we have other blogs to read, and can safely ignore pretty much anything Atwood says. I even like XML a little more than I used to, just because he wrote a blog post against it ;)
- davidmathers 18y agoWhat you just said is exactly what Atwood is saying, and what Raganwald is arguing against. If you freeze any moment in time then elitism always seems like the most rational choice. But if you take into account the passage of time then elitism is a losing proposition.
- raganwald 18y agoStrangely, I find myself nodding in agreement with both of you. I simply must get back on my meds. Thinking... I don't know what Atwood really meant, it's just a blog post, but I do think there is a real distinction between "Hey you! Don't do that, it's dangerous!" and "You shouldn't be allowed to do that, you're not qualified." After all, I wrote this: http://weblog.raganwald.com/2008/04/is-strictly-equivalent-to.html http://weblog.raganwald.com/2008/04/is-strictly-equivalent-t... Which is definitely a kind of "Don't do such and such" article. But while I actually write code to make things I like easier, I have no interest in sitting down and writing code to make the things I don't like harder or impossible.
- cia_plant 18y agoAtwood seems to equivocate between "monkey patching," "monkey patching built in classes like String," and "metaprogramming." There are good reasons to be careful of monkey-patching, especially monkey-patching of built in classes, but they are essentially identical to the reasons that you want to be careful of all global state. There are other forms of metaprogramming, such as macros or templates, which are more local and safe. I guess the real issue is between "make potentially bad choices annoying and difficult to use, so that programmers feel bad about using them," versus "support all programming as well as possible, trusting the programmer to avoid bad patterns." I think that the latter attitude is more realistic: a determined bad programmer can write bad code even in Haskell or Ada or Java, and sometimes those "bad" patterns are useful (e.g., gotos are a great way to write a DFA).
- harshavr 18y agoThe thing that the original article(by atwood) seems to be complaining about is not actually metaprogramming. It seems more like the standard gripe that functional programmers have about state, even though it is not phrased that way. He is objecting to dynamically changing some of the methods in the string class leading to subtle bugs as some code is written assuming the old string class and some using the new string class. Pheraps just explicitly define a separate custom-string class, or as he points out use mixins.
- deleted 18y ago[deleted]