By Peter Bell

Steve Nelson, XML, and Why DSLs Should Be a Required Subject

I haven't heard Steve's talk yet on "CFC's are the frameworks", but after Jeff Houser took a quote and ran with it, I felt it might be worth providing a perspective on the difference between a CFC and an XML schema - because they're often just two different ways to write the same thing . . .

An XML file can be seen as a Domain Specific Language for describing the solution to a problem within a constrained solution space. You can use XML to describe anything from controller functions to workflows to bean dependencies and configuration information. If you looked at the DTD, Schema or Relax NG description of the grammar, that would describe the underlying (abstract) grammar of any given XML document.

An important distinction here is between concrete and abstract grammars - and stay with me because this is actually quite useful. An abstract grammar describes the kinds of conceptual structures that a given language allows (for most languages you also have to add semantic constraints as often there will be syntactically valid statements that have no useful meaning). A concrete grammar is a particular way of writing an expression that conforms to that abstract grammar. So, for example if you have a DSL for describing workflows, I could write that using CF Script, a text file using indents and spaces for meaning, in XML or I could draw a diagram and these all might potentially be different valid concrete syntaxes to describe the same abstract grammar - to put it simply, they would all be valid, transformable ways of saying the same thing using different characters (or shapes) to denote the same underlying intent.

I have no idea what Steve is going to be saying at Frameworks, but one thing I will say is that a set of calls against an API can be thought of as a different concrete syntax which could be used in place of XML. For a certain subset of abstract grammars, an API can be a very appropriate concrete syntax to use, but you are still having to learn the same vocabulary (the abstract grammar and any associated semantic constraints of your DSL) to call your CFC or base class or API as you would be to write an XML file.

There are definitely strengths and weaknesses (as well as personal preferences) when choosing the most appropriate concrete grammar for a given DSL, but whether you use CFCs or XML, the language still needs to be defined and learnt. So the quote Jeff pulled:

In my opinion, using XML files to create a new framework programming language has more drawbacks than benefits. The biggest drawback is that the developer needs to learn yet another series of tags and syntax and keywords in order to use a framework

to me seems short of the mark (although I could be misunderstanding Steve completely). To me, there is a huge benefit in the expressiveness of a well designed DSL (whether you provide it as a CFC with a set of methods, an XML document, a custom textual syntax or a UML diagram). It reduces the number of characters required to express intent, cuts down on the likelihood of syntax errors, keeps your code DRYer and provides a host of other benefits. But whether you want to implement a DSL using an API or XML, the developer will need to learn your abstract grammar. I guess you could argue there is a minor benefit in not having to learn the concrete syntax of XML (although how hard are angle brackets to get?!), but just as you need to learn the tags and attributes for an XML concrete syntax, you need to learn the exact same concepts expressed using methods and properties if you implement the DSL using an API (probably a CFC) as your concrete syntax, so you can't beat up on XML for that.

I will be sure to attend Steve's talk next week to see what he is talking about and will post back here as I learn more!

Comments
I just wanted to clarify that I haven't seen Steve's talk yet either. I pulled the quote from an interview with Steve that was in the latest Teratech newsletter promoting the conference.

This whole concept of "DSLs" is new to me. Are there any resources, aside from your blog?
# Posted By Jeffry Houser | 1/24/07 7:31 PM
Best resources are books: "Generative Programming" is the definitive and "Software Product Lines: Practices . . ." is good. You could check out the Code Generation Network (codegeneration.net) and if you Google "domain specific language" you'll get loads of hits. Check out Martin Fwlers piece on Language Workbenches - it gives a good intro at:

http://www.martinfowler.com/articles/languageWorkb...
# Posted By Peter Bell | 1/24/07 7:38 PM
Two more resources:

Martin Fowlers Bliki:
http://www.martinfowler.com/bliki/DomainSpecificLa...

and Wikipedia:
http://en.wikipedia.org/wiki/Domain-specific_progr...

You might also want to google "language oriented programming" to get the "big idea" and check out anything recent by Charles Simonyi over at Intentional Software.
# Posted By Peter Bell | 1/24/07 7:40 PM
Peter,

When I read the quote you referenced, I had the same thought as you, namely "But whether you want to implement a DSL using an API or XML, the developer will need to learn your abstract grammar."

I agree there, but I'm still not loving the XML as DSL (not that it can't be done, I just prefer to do it in a less ... cluttery? ... way, if possible).

On another note, I seem to remember Martin Fowler having a good article on DSLs specifically... I don't have the reference, but ... nevermind, looks like you linked it in the 2nd comment you made. =)
# Posted By Sammy Larbi | 1/25/07 12:19 AM
Yeah, I don't love the concrete syntax of XML, but I just wanted to distinguish between abstract and concrete grammars as it makes the argument clearer. Personally I'm playing with a number of languages and syntaxes to try to find the way I prefer to express intent. I quite like the Python style approach to making white space and indentation meaningful as it clears out a lot of the clutter, but I'm still trying to decide (a) how to best express intent (for me) and (b) how to handle the whole parsing issue as CF isn't exactly the optimal language for parsing but I'm resisting getting into Antlr/lexx/yacc/whatever . . . I'm looking for the 30 second solution to parsing (including learning time :->).
# Posted By Peter Bell | 1/25/07 3:43 AM
This CFC stuff i've been playing with has some nice added benefits. For example, i've been playing quite a bit with direct CFC Socket connections. I've been experimenting with building Windows specific apps that open a connection to the server and keep it open, like an Instant Messenger does. Then as events occur on the server data is instantly sent to the Windows application, no time delay at all.

Anyway, the code for the "socket" CFC and a normal web based CFC are all organized in the same manner and can talk to each other like nothing is different. It creates very nice consistency of the codebase even in applications that span technologies.
# Posted By Steve Nelson | 1/25/07 12:50 PM
Of course, you could also do that writing an external DSL and parser . . . the biggest limitation of in-language DSLs is that you don't get the same "free" validation or limitation of syntax (unless you write a pre-parser which actually opens your CF files and parses them and throws up any syntax issues which I'm guessing you're not doing). But in-language DSLs definitely have their place and the ease of creating them means it is easy to play with your grammar by modifying your method signatures so it is great for prototyping.

Certainly will be interesting to find out more - I'll be at frameworks and will definitely try to catch your presentation! Anywhere else we should look for documentation on your approach?
# Posted By Peter Bell | 1/25/07 1:05 PM
"Of course, you could also do that writing an external DSL and parser"

Peter, I laughed when I read that. I mean, it just sounds so non-chalant!

=)
# Posted By Sam | 1/25/07 1:32 PM
Well, that's why I'm working on tooling to simplify that stuff :->
# Posted By Peter Bell | 1/25/07 2:37 PM
Peter i'm planning on starting with getting my presentation and sample code posted after the conference. Like everything in life it's just a matter of making the time to do it.
# Posted By Steve Nelson | 1/25/07 3:35 PM
Know how THAT goes! Looking forward to meeting you at the conference!
# Posted By Peter Bell | 1/25/07 3:58 PM
btw, i think we're (Webapper) throwing the usual "Party in our room" at the framework conf. Patrick is going to post something on our blog shortly. We'll bring the beer, you bring yourself.

The last time we did that some Romanian guys were opening bottles with their teeth. Those guys were out of control!
# Posted By Steve Nelson | 1/25/07 4:04 PM
Sweeet! I'm a frameworks conf newbie, but always like to support a tradition!
# Posted By Peter Bell | 1/25/07 4:25 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.