Mon

Jul 10
2006

Nat Torkington

Nat Torkington

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: nitty gritty tech  | comments: 4   | Sphere It
submit:

 
Previous  |  Next

0 TrackBacks

TrackBack URL for this entry: http://blogs.oreilly.com/cgi-bin/mt/mt-t.cgi/4779

Comments: 4

  Pat Allan [07.10.06 07:45 PM]

I would love to see something like Javassist for C#.

Metaprogramming is just another feature in Ruby/Rails that makes coding in C#/ASP.NET a little bit more frustrating.

  dave mcclure [07.11.06 12:02 AM]

love that rush limbaugh line.

"keep up" the good work nat ;)

heh.

  rektide [07.11.06 08:13 AM]

Pat Allan:
Uh, take your pick, RAIL or CECIL. I'm still not sure whether CECIL is allcaps or not.

Neither allow you to edit the source code, ala Javaassist, but that is to be expected. There are a plethora of languages which all compile down to CLR. I'd like to see someone even try and infer "source code" out of a Boo generator.

My biggest beef is Mel's biggest beef. None of these tools allow you to modify your code when and where it counts: at runtime. They're simple instrumentation tools. Compiled (v. interpretted) dynamic languages would be amazing, but the tooling is not there.

Starting to wish I could make it to OSCON.

  Pat Allan [07.11.06 05:54 PM]

rektide, thanks for that - I didn't find either of those in my googling yesterday.

Post A Comment:

 (please be patient, comments may take awhile to post)






Type the characters you see in the picture above.