
My analyst warned me, but metaprogramming was so beautiful I got another analyst - raganwald
http://weblog.raganwald.com/2008/07/my-analyst-warned-me-but.html
======
icey
Whenever 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._

~~~
Herring
You 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.

------
cia_plant
Atwood 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).

------
akeefer
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.

------
harshavr
The 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.

------
gruseom
Isn't Atwood one of the types who get all indignant about the "Blub" argument?
Maybe he should think twice before utterly confirming it.

~~~
jrockway
The 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
What 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
Strangely, 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-t...](http://weblog.raganwald.com/2008/04/is-strictly-equivalent-
to.html)

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.

------
andreyf
What 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
I'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
Summary of argument: _Your_ opposition to ( _whatever_ ) is just like the old
priestly order's opposition to the _printing press_.

~~~
raganwald
Yes, 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.

