14 February 2008

Markaby vs templating, with a remark on DSLs

I tried out Markaby ("MARKup As ruBY") the other day because I was getting completely tangled in my rhtml. It's a DSL for generating HTML from Ruby. I like it: it's much less verbose than templating, and it's a lot easier to read. Template enthusiasts might argue that Markaby does not enforce proper separation between markup and content - so a UI designer will be unable to work properly. Sorry. I only know of projects where the developers are also the HTML/CSS designers. This seems to be standard practice for in-house projects at large organisations, as well as a necessity for tiny organisations who can't afford more people. The mythical UI designers - so real in the Freemarker manual I start to worry they'll grab my keyboard - haven't turned up for work yet ...

Unfortunately, it's not so easy to write. At the risk of being scorned by the rails community I will dare to mention that I use Intellij for all my ruby coding (yes, ruby coding. I know it's the "intelligent java editor"), and it has great support for HTML - it autocompletes html tags, attributes, a little bit of javascript, and a heap of CSS. Even colours. It's, like, awesome.

But I'm not talking about Intellij today, I'm talking about Markaby. The problem is, Intellij doesn't know (yet) how to autocomplete Markaby. When I write

div.selected(:id => "foo_#{foo.id}", :style => "position:abs___

and try to complete from here, Intellij doesn't realise this is the position property of a HTML style attribute, and it can't tell me that the valid completion is absolute. What's more, I can't control-click selected to navigate to the definition for this CSS class.

I'm sure the smart guys at Intellij will have this one figured out pretty quickly if Markaby gains market share. As Martin Fowler discusses in detail at Language Workbenches, tool support for DSLs is a general problem. But this absence of support doesn't mean we should reject either Markaby or DSLs generally.

One of the reasons we choose one programming language over another is because of how it helps us think. Lisp/Smalltalk/Ruby are powerful because they get completely out of the way. Well-designed DSLs are useful because they focus our attention on the problem at hand. The languages that win are those that allow us focus while staying out of our way. The value of the language is independent of the availability of tools for it. Java was around for a long time before Intellij, and indeed Spring and Hibernate were around for quite a while before Intellij provided specific tool support for those frameworks.

Tool support for a DSL is often more expensive than the DSL itself - so it will be unsurprising to continue seeing new unsupported DSLs for the foreseeable future. That way the industry invests in tool support only for those DSLs that actually take off.

Which I hope Markaby does.

No comments:

Post a Comment