Saturday, May 13, 2006

The Power of Blocks in DSLs

Charles Nutter has a great blog entry on a Bytecode DSL written in JRuby. If you look closely at the code, he's making great use of Ruby's blocks. It makes the code succint and powerful. Oh yeah, it's fun, too! The example could be done in any dynamic language with closures (Groovy for example).

I'm loving the examples of DSLs coming out of the Ruby community right now. They show off the expressive power of method_missing and blocks (or doesNotUnderstand: in Smalltalk). There's a lot of power in those two simple features that allow you to express higher level concepts easily.

2 comments:

Isaac Gouy said...

"The example could be done in any dynamic language with closures"

Could the example be done in any statically type checked language with closures?

Blaine Buxton said...

Yes. You can do anything in a statically typed language that you do in a dynamically typed one. You'll just type more (no pun intended).