What is Domain Specif Language (DSL) and how to use with PHP

Martin Fowler about DSL

Martin Fowler talking about Domain-Specific Language (DSL) in Rio de Janeiro

About 2 weeks ago, I went with my colleagues at AWM Interactive to an event with Martin Fowler to hear him talking about Domain Specific Languages (DSL).It happened on monday, June 14th in PUC-RIO (a university in Rio de Janeiro).

So, what exactly is a Domain Specific Language? It’s a programming language (or a specification language) that documentates and provides, in a user friendly way, information to a scripting language. It’s intended to give software the information it needs to execute by giving the engineer an easier way of inputing this information.

I currently use Zend Framework to develop websites and web applications and it has two DSL implementations, in my point of view, as I write this post: the documentation of each class and methods (wich are better used with an IDE like Eclipse) and some classes like Zend_Config and Zend_Translate, wich can read multiple type of files so they can be written in plain idioms, like portuguese or english. These type of files includes .ini, .xml, .csv and you don’t need to learn a specific syntax, but the format only.

DSL are important to help in different kind of work. For example, imagine if you had to give a professor all your PHP files so he could translate, in an array, the many languages you would like to have your application? The array would be huge if the professor could understand the code without messing it. Or, worst, imagine if the account manager should give to an outsourced programmer the host, login and password to run the application (and to have it connected to database)? There goes the security away, right?

Using DSL, you can have a programming language loading the specification file in runtime with the configuration the application may need to render properly. Or the information it needs to connect to a database. And you can have several ways to do that. Using XML, INI, CSV or even a simple TXT.

Another example of DSL and, if you use PHP, probably you use it, is SQL.It helps you (and the scripting language)  to perform database queries.  Have you ever wondered how would you make a query without an Structured Query Language? Well, I don’t!

So, while technology development gains maturity, DSL becomes more important to help business integrating different departments. By the way, have you ever thought how a designer could change the color or font-family of a website without CSS? A lot of HTML (or PHP, if we are talking about dynamic pages) knowledgments would be necessary, right?

I won’t go deep in this hole, since this is my first article and I need improvements, but if you’d like more reading, try the following links:

Recent Posts