Metaprogramming in Ruby and Java

Metaprogramming is modifying your programming language to make it fit your problem domain. Lisp started it, Perl’s source filters did something along those lines, but Ruby’s got it in spades (caution: Why The Lucky Stiff content behind that last link). In the last few weeks I’ve been pounding through Ruby like Rush Limbaugh through an Everest of Viagra, and I wish I’d seen Glenn Vanderburg’s session (PDF!) at OSCON last year about metaprogramming in Ruby. If you’re a Java programmer, you should check out Howard Lewis Ship‘s session at OSCON on metaprogramming in Java.

Howard uses HiveMind’s inversion of control container (Howard’s the creator of HiveMind) and the Javassist bytecode library. Javassist is, frankly, terrifyingly powerful. I don’t know what to be more amazed by: that Javassist exists at all, or that it’s a subproject of the relentlessly Enterprisey (and therefore sober and reliable and not at all meant to be terrifying) JBoss. That’s like the Betty Ford Clinic funding research into more efficient methods of producing crystal meth. Javassist reminds me of the alt.folklore.computers warstories about programmers who know too much about their execution environment.

If metaprogramming is too much like performing open brain surgery on yourself, you might be more comfortable with Howard’s sane contribution to OSCON: Building Java Web Applications with Tapestry (Howard also created Tapesty). No meth and no autocortical cauterization required. Viagra optional.

tags: ,

Get the O’Reilly Programming Newsletter

Weekly insight from industry insiders. Plus exclusive content and offers.