I’m a big fan of domain-specific programming languages when developing for a very specific domain. Game development is a nice example, because you have a lot of rules and details to present do the player, that influence the game flow and game play. You could write these rules directly in the game engine, but you would lose flexibility.

A better approach could be to write a more generic game engine that knows how to handle the game rules via a DSL. There are games that use a scripting language to add flexibility to the game engine. But I still prefer some kind of DSL that maps directly to XML (or vice-versa), because of the following advantages:

  • Forcing all the rules to be in a DSL is great to enforce loosely coupled systems. The game rules will often change and we want no impact on the other modules
  • You can use a language specially created to represent the application logic, instead of using a general purpose language - you gain in software quality, readability and maintenance
  • You can give this language to the business guys; you can have the application logic written by the people that really know the business rules. Note that the DSL can be visually represented with some modeling tool, that transforms it to XML
  • Having all the game rules in one DSL could prove quite useful to generate several resources: base implementation structure for several languages(C# and Javascript for example), unit tests for the implementations and documentation

Given these advantages, I think that DSLs should get way more attention.

In fact, there are people that consider that this new language-oriented paradigm will be the next programming paradigm.

Related Posts

5 Responses to “Domain-specific programming languages”

  1. Bruno Antunes Says:

    This is all good, but the skills needed to construct them are steep. What kind of help does one have to implement a DSL?

  2. Pedro Santos Says:

    In Orion’s Belt we map the XML to C# (each XML element maps to an action that maps to a class). It’s not very complex, but on other scenarios it could be.

    So yes, there aren’t many tools out there to assist in the creation of a DSL, except maybe the Microsoft Domain-Specific Language Tools (haven’t tried them).

  3. Vlad Says:

    Tell the business guys that they’ll some sort of special power with this and they’ll lick the floor you step on. :)

    Ah, and if you don’t tell them that, they will try to push it to back to you.

  4. Pedro Santos » Blog Archive » Designing a DSL Says:

    [...] it’s true that a DSL has many advantages, it’s also true that designing a DSL is very difficult. One should have full knowledge of the [...]

  5. Farley Knight Says:

    Why XML? I attempted to write a DSL for PyGame before, but I quickly found the process very tedious and error prone. You’re much better off with something more light weight. I’d recommend that if you’re planning on rendering code into data, go with s-expressions.