Domain Specific Languages for Desktop Apps
Domain specific languages have been popular for some time now, but for how long they’ve been popular is a fuzzy question, with an equally fuzzy answer. There’s considerable debate over what a DSL really is, and when a language crosses the line and stops being targeted towards a niche and starts being general.

The most broad definition of a DSL is a language designed to solve problems in a given problem domain. This is in contrast to a general programming language (such as C, or Python), which is designed to be applicable to all problem domains. The problem of defining a DSL appears when you need to define the boundaries of your problem domain: XSLT was initially designed to modify XML graphs, but over time its problem domain extended into string manipulation, filesystem interaction, and other areas.
This being said, a DSL is characterised by a few core elements:
- Solving a problem in the DSL’s problem domain is easier and simpler than using a general purpose language.
- DSLs are often less comprehensive than a general purpose language.
- DSLs are typically designed for use within a larger system.

Sometimes a general purpose language can become a DSL. Lua’s loose syntax and simple data structures (it only has one, the table) allow it to be used as a generic configuration file format, which can be read quickly and with little computational or programmer effort. The paper that introduced Lua showed examples of it being used as a DSL that defines GUIs, as well as configuration files for math programs.
Another interesting example is Ruby, which features an even looser syntax than Lua, but more complex data structures. A popular, simple example are the attribute functions, which define accessors for class variables. A class need only define somewhere in its body:
attr_reader :some_variable
And that class now has setters and getters for ‘some_variable.’ More complex examples are present in Ruby on Rails, in which entire data models are constructed through similar syntactic patterns.

What if we looked at the Mac desktop as a problem domain? It makes sense, when you think about it. While there are an infinite number of tasks that users can do with their computer, there is a finite number of tasks that users often do: checking mail, browsing the web, writing, communicating, and so on. These tasks can be decomposed into task primitives; for example, a simple RSS reader performs three things: it downloads a file, parses it, and presents it as a list in a window. A web browser is more complex, but can be reduced to the primitives of downloading a web page, displaying it, and allowing the users to select what to view next.
Could a DSL be written that allows users to express these tasks and recombine them, with the versatility and ease of use that DSLs offer? Over the next couple of weeks, I will be looking at how we can do just that, and how it’s leading up to the next great revolution in how human beings get things done on their computers.
Further reading:



[...] Secret Lab - Do More, With Less, Part 1 (tags: dsl language langauges mac osx programming lua ruby development scripting) [...]
Pingback by links for 2008-06-09 — June 8, 2008 @ 5:45 pm
[...] http://secretlab.com.au/do-more-with-less-part-1/ [...]
Pingback by Domain Specific Languages for Desktop Apps — June 9, 2008 @ 8:50 am