The amazing adventures of Doug Hughes

What is a DSL?

Peter Bell has been talking about domain specific languages for some time now, but I expect they are still a pretty foreign concept to many people, myself included not too long ago. However, if you have used any of the popular ColdFusion frameworks like Model-Glue, Mach-II, ColdSpring, etc., then you have actually used a DSL in their XML configuration files.

To my current understanding, a DSL allows you to take a generic set of application code and configure it to a specific use – hence the words domain specific. That configuration may be done via XML, a text file that is parsed, or even code. The big thing here is that you are writing configuration for a specific problem area or domain.

On a recent project, we were faced with 50+ simple CRUD style lookup tables that all had to have the same style list, create, and update form user interfaces. So, instead of creating individual little DAO, business, and service objects as well as the same cfm views over and over, we are adopting a generic “object” approach where there will be a single DAO, business object and service object, which when given an “object definition” via an XML document, will become smart objects and all of the sudden know that they represent a certain data element.

By doing this, the actual code we have to maintain is limited and making fixes and tweaks that much easier. The UI design is also much simpler in that there are only one set of views, so changing styles etc. can be done in one place and be applied across the board. It is also much simpler to make changes to the different objects managed by the system, whether that be adding a new object definition or changing the properties of an existing object definition.

So, are people using DSLs out there without really knowing it? What are some problem areas that you have addressed with a DSL? I know Peter Bell has discussion building whole applications before and while I am not to that point yet, I am very interested.

Comments on: "What is a DSL?" (11)

  1. take a look at the modeling edition of eclipse 3.4 and the tools that come with it (EMF, GMF) to build DSL editors.

    Like

  2. on the same note, we have built a few internal prototypes of dsl’s using GMF. my personal feeling is that all generated code requires extension points, in case you regenerate – you do not want to loose the code you wrote. Annotations is one way of managing DSL’s in code, but the concept behind the whole Model Driven Architecture (MDA) is well discussed on several lists inside the eclipse foundation. this is a long cpnversation, but is something which is the future to some extend.

    i find it ludicrous that people still code models and service layers, by thinking a bit in UML2 sequence and state diagrams you can easily see how these things could become generic with transforms and controllers as your extension points. anyway, nuff ranting, i don’t even code CF.

    Like

  3. Doug Hughes said:

    Jeff – You might want to check out Groovy. They have some DSL concepts built into the language which are quite different from what you’re discussing.

    My understanding is rather limited at this point, but as an example, GORM, the Groovy/Grails ORM build on top of Hibernate. In this case they use on missing methods to allow for dynamic functions like getFooByBar() or getSomethingByFooAndBar(), etc.

    You can also add your own methods via metaClasses to finalized objects. The book I’m reading gives an example of adding a contents() method to string which would treat the string as a path. Thus, you could read a file by using ‘foo.txt’.contents().

    Very interesting stuff.

    Like

  4. I heard the term Domain Specific Language quite some time ago, but I think I have always defined it a bit differently. Here is the WIKI article on it:
    http://en.wikipedia.org/wiki/Domain_Specific_Language

    To me, a DSL is a set of instructions and syntax definitions and a corresponding interpreter for them which solve a very specific problem. CFML in general is said to be domain specific since it is a language intended pretty specifically for creating web pages. (Though it has arguable grown a lot since the early days).

    The concept of a reusable CRUD interface using generic forms, and synthesized objects is a design pattern or framework to me, not a DSL. Now, I guess technically the XML files themselves might represent a sort of DSL within them since they follow a specific format and syntax to define your components, but I’m not sure if I am sold on that theory yet since I don’t really consider config files to be a “language”. I would consider something like TQL (Transfer Query Language) to be more of a DSL.

    Like

  5. I just spent the past hour Googling DSL’s and such and have came to the conclusion that my definition of a DSL was a little too narrow. Apparently, Domain Specific Languages come in two flavors. Internal and External. My view of DSL’s until now fell mostly under the External category. An Internal DSL is described by Martin Fowler as “a particular idiom of writing code in the host language”. That is a much looser definition than I had originally granted. The lines between an Internal DSL and an API or framework still seem to be blurred a bit. Here are two of the several links I perused:

    http://martinfowler.com/bliki/
    http://www.infoq.com/articles/internal-dsls-java

    Like

  6. Jeff Chastain said:

    @Brad – I don’t claim to know everything there is about DSLs, so you may be right. My understanding about DSLs is that they are a way to take a generic set of application code and customize / fine tune it to a specific problem or domain. So, in terms of the frameworks like MG and ColdSpring, by themselves they are just a generic set of code. Once you add the XML configuration to them, they become tailored to your specific use case and become more useful.

    I have heard the CF is a DSL before and that I don’t really buy. Sure it is designed for web applications, but I still feel like it has more characteristics of a general programming languages rather than a DSL. It might not be quite as broad as Java or C#, but to me it still seems to be closer to that than what I know of of a DSL.

    Thanks for the links. I was reading several more white papers on this last night, so I will add those to my list.

    Like

  7. @Brad
    generating code (not necesarily CRUD) means you have defined your problem domain (i need to have an app which does this and this and that) hence a dsl being relevant.

    Once again I would recomend people to look at the eclipse 3.4 modeling edition and checking out JET, EMF and GMF, the power in this is truly incredible

    Like

  8. It is important to realize that MDA isn’t the only way to approach DSL’s and Domain Specific Modeling. It is one approach, but honestly, within the DSM community it’s not very popular as UML isn’t the ideal way to raise the level of abstraction above that of classes. I know that it can be extended using stereotypes, but in practice I’d recommend starting by defining your DSL and then throwing together a simple concrete syntax (for external DSLs, XML is really easy to parse to get start5ed with), and then writing an interpreter or generator you’ll find it much easier to get started with and you’ll be much more likely to create a language that reflects the needs of the domain rather than those of your UML tooling.

    If you’re looking at Eclipse based tools, check out openArchitectureWare. They’re folding it into one of the Eclipse modeling projects, but it’s much more flexible than the MDA stuff.

    I think the definitive book is still “Generative Programming” by Krysztof Czarnecki, although JP Tolvanen and Steve Kelly just published a great new book on DSM. As the people behind metacase which has been solving these problems for over a decade, I’d thoroughly recommend their book:

    I’d also thoroughly recommend the Code Generation conferences run by Mark Dalgarno every year in Cambridge. Next year Steve Kelly and Markus Voelter will be the keynotes which will be excellent as they’re two of the best presenters on code gen.

    And Jeff, got your email – promise to get you a response soon. Just landed in the UK yesterday so been a little busy, but taking train down to London today so I’ll see what I can do 🙂

    Like

  9. A couple of other comments. I typically favor external over internal DSLs. Mark Drew pointed out an interesting article on embedding DSL support in Eclipse JDT, but I still prefer to pull my DSLs out of my application code as then you are programming language and language version independent and have the greatest flexibility in the possible transformations you can apply to your DSL statements. Turning an XML file into a pretty diagram or a set of docs is trivial. Trying to do the same by parsing Groovy or Ruby based internal DSLs can be anything from fraught to impossible depending on how you implemented the DSLs!

    FYI, this was the article Mark recommended:
    http://www.eclipse.org/articles/article.php?file=Article-AutomatingDSLEmbeddings/index.html

    Like

  10. @peter

    yes, MDA is one approach, building a configurable application through the use of config systems is a great start on defining dsl’s and i agree that making a UI is a pretty low priority in the greater scheme of things. evolving a dsl however and making it usable to a broader base requires tools (people are pretty slow at adopting and understanding pure xml config systems from my experience)

    the reason i keep pointing people to eclipse 3.4 is due to the fact that its a great introduction to a very broad topic.
    as i have not used ruby before i cannot attest what kind of reflection capability it has, but reflection always comes at a high cost ito processing.
    i am of the opinion that well defined dsl should be able to function both as a config system and a drive for code generation.

    another project i am also following is Eugenie which is a sub project of GMT, really simple quick setup, from model to editor, but with this ease comes limits of course.

    this is a great topic and i will be keeping an eye on your blog.
    my focus has been flex for the last few years and i am frustrated with the toolset and most of the frameworks out there.

    thanks for the links and book recommendations

    Like

  11. Marcuski said:

    http://concealer.mybrute.com
    Check out this cool mini fighting game

    Like

Comments are closed.

Tag Cloud

%d bloggers like this: