As a programmer who spends most of his time writing code that helps other people to write code, I’m pretty interested in domain specific languages. In fact, I have a couple of modules we use at work that use them. That’s how I ended up in Domain Specific Languages in Perl, presented by Jesse Vincent of Best Practical.
Domain specific languages (DSLs) are languages designed for specific programming tasks. A couple of well-known examples of DSLs are SQL and regular expressions. However, today, Jesse is talking to us about “Englishy” DSLs, which he’s been very interested in lately. Additionally, these are DSLs that are internal to Perl. Instead of parsing a DSL and executing it, they are instead implemented by playing with Perl’s syntax and taking advantage of Perl’s parser (and having all of Perl’s features available in the DSL).
The two main goals when implementing a DSL in Perl are,
- Does it feel good?
- Can we actually do it?
The first big DSL is Jifty::DBI, an object-relational mapper for Jifty. For the folks at Best Practical, it was a fun learning process in tweaking Perl to look the way they wanted it to while still declaring the database schema in an intuitive, pretty way.
The Template::Declare module is flat-out awesome. I’ve seen it before, and I’ve never taken the time to play with it. How stupid have I been? Coding HTML templates in Perl is cool, and something I would happily do (I don’t really like writing HTML).
As if that weren’t enough, in comes Jifty::Dispatcher. Modelled after Mason’s (auto|d)handler files, it will manipulate web application requests and take care of dispatching processes. I really like the DSL used here. It’s very declarative, removing the infrastructure entirely, which is something I’m very interested in doing in my code right now. I must be getting old; I’m more interested in telling the computer what to do, rather than how to do it, these days.
Testing web sites is ugly, and it sucks. That’s what Test::WWW::Declare is for. It’s a beautiful module. Sessions, flows, declarative statements to define the web flow. So very awesome.
I can tell that the Best Practical folks have seen Damian Conway’s Sufficiently Advanced Technologies talk. The moral of that story is, write what you want to see, and only then figure out how to make it work in Perl.
I’m sold. As soon as I get home, I’m going to work on porting my start-up company’s web site with Jifty. Jifty is, well, absolutely nifty.
At the end, Jesse showed us his own domain specific language to define his slides. It’s awesome. I want it for my own talks.