Wednesday, February 24, 2010

Are DSLs simply XML Hell?

DSL : what is it ? You have used a Domain Specific Language. Trust me. Demystify DSL: it simply a narrowed and specific semantic problem that solves a narrow set of problems.

Model-View-Controller (MVC) is a common pattern for Web development, Apache Struts has come to the rescue in the past. Each Struts application uses a configuration file (XML). The language (dialect) of the XML specifies exactly how the MVC pattern would be implemented for the specific implementation this is DSL.

Object Relational mapping was a common problem made worse by general purpose languages and APIs(e.g. Java and JDBC), along came the a natural ORM (e.g. Hibernate) with specific configuration files that mapped POJOs to Tables. The configuration file (XML) supported a dialect (ORM DSL), of course it was not called DSL back then they were simply configuration files (aka XML Hell).

DSLs don’t necessarily mean XML. For example, running rules in Java was ‘simplified’ by a Rules Engine implementation e.g. Jess. This used a DSL - Jess 7 has its own declarative XML rule language called "JessML" (a DSL).

What is the advice for people who are trying to learn DSLs and master them ? Don’t. Try not to master DSLs instead focus on the domain of the problem, understand the software architecture and how it fits, understand what the pattern of problems are, figure out how best to apply design patterns that solve them. Understand the pain of the domain (e.g. web-site design, object-relational mapping framework, rules etc), understand the inefficiencies, then focus on an over all design within the domain that solves most of the problems. Finally, look at the DSL as a tool to solve the problems in a specific efficient way. Then you will see there is no XML but simply a graceful solution.