By Peter Bell

Joe Rinehart, XML, and Why DSLs Should Be a Required Subject (!)

Joe just posted an article clarifying that (a) Model Glue doesn’t need XML and (b) that XML provides real benefits over scripting for configuration. Both of those statements are absolutely correct.

However, he also made some statements that weren’t . . .

He said:

When I started writing Model-Glue, I shared the view of many others where I just didn't see why XML should be necessary to use a framework. I mean, I already know ColdFusion, why not just script together the events, listeners, etc? Let the CFCs themselves be the framework.

I certainly know that experience as I’ve been through it myself and I now believe XML config files provide a good number of values for a wide range of use cases.

He then compared using scripting to an XML based approach and when looking at the benefits of XML he noted:

1. I could create my own syntax that was Model-Glue specific, expressing multiple lines of CFML script in a single tag.
2. I abstracted my application from the framework's API.

In fact, the first statement is a general benefit of a Domain Specific Language. Creating a method call does exactly the same thing. As for the second, all he has done is move the grammar of his configuration DSL from an API to XML. He could have done that equally well by creating a set of cfcs with method calls corresponding to his XML grammar that then call the underlying API (if for some reason there is a need for the two layers). Of course, if you change the API (in a way that isn’t backwards compatible) applications will break. Try changing the names of all of the tags in your XML grammar or requiring extra arguments to them and it’ll break in the same way. If you change the abstract grammar of your DSL, you’ll break your existing code – irrespective of whether your concrete grammar is expressed in XML, ColdFusion or UML.

None of this should be taken as supporting an in-language API style DSL over an XML DSL. Both concrete syntaxes have strengths and weaknesses that Fowler covers pretty well in his Language Workbenches and DSL pieces, but I do wish people would make the distinction between abstract grammar and concrete grammars and distinguish syntactical from fundamental issues more clearly.

Oh jeesh – I’m now officially a grammar nit for computer languages. How sad . . . .

Comments
Bingo! I feel that XML has been used in a lot of these apps because...well...it sounds cool to say "I use XML to configure my app". Why not have the configuration in an API, that with the right IDE could be self documenting. XML at it's very heart is a data format for transferring information between disparate systems that don't recognize the others objects. Heck, it's not even easy for a human to write and read, ini files or yaml files would be a much better choice for configuration in my opinion.
# Posted By Marlon | 1/25/07 11:09 AM
Well, to be fair, XML has a number of benefits. It is an exteral language with a self validating grammar so a class of errors can be caught for free just by describing the schema of the language. As an external DSL it is also deliberately limiting, stopping you from doing something silly in the underlying language. Read anything from Martin Fowler comparing internal and extermal DSLs and you'll see some of the trade offs.

Fact is I am NOT saying XML is a bad choice - I'm just saying that some of the reasons that Joe gave for it being a good choice are wrong. There are plenty of other good reasons to use XML. Also check out stuff like the spring 2.0 IDE project. No reason why you can't have IDE support for XML syntaxes.
# Posted By Peter Bell | 1/25/07 11:21 AM
I for one am looking forward to Steve Nelson's presentation called "CFCs are the Framework" at the Frameworks conference in just a week from now! I am guessing that all of this API DSL v. XML DSL is being generated by Steve's new CFC implementation of Fusebox.

I think Joe's experience of starting out not wanting to use XML as the API for a framework resonates with must of us, which is why I think the community should give Steve's new implementation a chance and why I am so excited about hearing his presentation on it next Thursday.

The two most salients point that Steve makes for moving to a CFC API is that an XML API necessitates redefining existing ColdFusion as well forcing devlopers to learn the tags, syntax and keywords of the API (Fusebox currently consists of 20 tags and over 100 attributes) and many of these tags exist elsewhere in ColdFusion with different attributes. Why are we reinventing the wheel when Frameworks are all about code-reuse and conventions?

As a bonus, Steve's proposed Fusebox implementation does not require any core files!

I am currently building my own blog, but you can be sure that I am going to post about this as soon as I get it ready (the url is webmusings.org).
# Posted By Aaron Roberson | 1/25/07 12:59 PM
Hi Aaron,

I'm also looking forward to Steves talk, but there is a material misunderstanding that keeps coming up. If you want to have 20 "commands" in your language, developers will have to learn those 20 commands. Doesn't matter whether they are XML tags, CFC method signatures or different shapes in a UML diagram. If you have a grammar with 20 elements, irrespective of syntax (XML, ColdFusion, pretty pictures, whatever) developers still have to learn those 20 commands. Putting them into an API does NOT make them go away it just changes the set of characters you use to call them.

In additional, with XML, you get free validation against a schema and people are stopped from just hacking in their own ColdFusion which is not possible with an in-language DSL unless you write a pre-parser which introspects your CF scripts pre-runtime to validate and clean up the CF code you write.

Fusebox is a bit of a special case as it has a bunch of tags that correlate to CF tags and it tries to provide control flow and looping which goes to the old dictum that every DSL eventually just becomes a badly designed general purpose language, but it is still important to distinguish between differences in abstract and concrete syntaxes.
# Posted By Peter Bell | 1/25/07 1:13 PM
Peter,

I just finished reading your post from yesterday with the same title except with Steve Nelson instead of Joe Rinehart. You're right, putting the commands into an API does not make them go away.

Also, I just read Jeff Houser's "Frameworks without XML" and noted Matt Woodward's and Joe Rinehart's comment 's stating that Fusebox is different than most other frameworks in that it has the application logic defined in XML while the "others" do not.

In honesty, the problem is not with learning new commands. We are developer's and we will always have to learn something - we rather enjoy it for some reason. Learning a framework is all about learning its conventions. However, just having a Model CFC, View CFC and Controller CFC and including the appropriate files sounds like a lot less overhead than having a bunch of core files that need versioning and maintenance. In fact (I am about to open another can of worms), It is a lot like Ruby on Rails.

I got to go before I get myself in trouble now...
# Posted By Aaron Roberson | 1/25/07 1:36 PM
Trouble is good - sparks argument -> distinctions -> learning *grin*

I don't think it is THAT much like RoR (which has its own problems) as in Ruby there are much more sophisticated metaprogramming features. It really isn't possible to build RoR with similar syntactic sugar because of language features CF just doesn't provide.

Anyway, will be interesting to see what Steve is up to!
# Posted By Peter Bell | 1/25/07 2:43 PM
Shameless plug: code.google.com/p/configcfc/
# Posted By jim collins | 1/25/07 5:14 PM
Shameless indeed Jim :->

Plug away, it's well worth promoting!
# Posted By Peter Bell | 1/25/07 6:01 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.