tags:

views:

574

answers:

7

I'm hearing more and more about domain specific languages being thrown about and how they change the way you treat business logic, and I've seen Ayende's blog posts and things, but I've never really gotten exactly why I would take my business logic away from the methods and situations I'm using in my provider.

If you've got some background using these things, any chance you could put it in real laymans terms:

  • What exactly building DSLs means?
  • What languages are you using?
  • Where using a DSL makes sense?
  • What is the benefit of using DSLs?
+5  A: 

DSL stands for Domain Specific Language i.e. language designed specifically for solving problems in given area.
For example, Markdown (markup language used to edit posts on SO) can be considered as a DSL.

Personally I find a place for DSL almost in every large project I'm working on. Most often I need some kind of SQL-like query language. Another common usage is rule-based systems, you need some kind of language to specify rules\conditions.

DSL makes sense in context where it's difficult to describe\solve problem by traditional means.

aku
A: 
Staale
+8  A: 

DSL's are good in situations where you need to give some aspect of the system's control over to someone else. I've used them in Rules Engines, where you create a simple language that is easier for less-technical folks to use to express themselves- particularly in workflows.

In other words, instead of making them learn java:

DocumentDAO myDocumentDAO = ServiceLocator.getDocumentDAO();
for (int id : documentIDS) {
Document myDoc = MyDocumentDAO.loadDoc(id);
if (myDoc.getDocumentStatus().equals(DocumentStatus.UNREAD)) {
    ReminderService.sendUnreadReminder(myDoc)
}

I can write a DSL that lets me say:

for (document : documents) {
if (document is unread) {
 document.sendReminder
}

There are other situations, but basically, anywhere you might want to use a macro language, script a workflow, or allow after-market customization- these are all candidates for DSL's.

Tim Howland
But do you actually have non-technical people doing that?
BobbyShaftoe
probably better to describe them as differently-technical; they are personalization wonks, not java coders.
Tim Howland
hope you know that your DSL is python.
Seun Osewa
@Seun, yeah, for that example it might make sense to embed Python or Lua instead of creating a whole new language.
dangph
+1  A: 

DSL is just a fancy name and can meen different things:

  • Rails (the Ruby thing) is sometimes called a DSL because it adds special methods (and overwrites some builtin ones too) for talking about web applications

  • ANT, Makefile syntax etc. are also DSLs, but have their own syntax. This is what I would call a DSL.

One important aspect of this hype: It does make sense to think of your application in terms of a language. What do you want to talk about in your app? These should then be your classes and methods:

  1. Define a "language" (either a real syntax as proposed by others on this page or a class hierarchy for your favorite language) that is capable of expressing your problem.
  2. Solve your problem in terms of that language.
Daren Thomas
+4  A: 

If you use Microsoft Visual Studio, you are already using multiple DSLs -- the design surface for web forms, winforms, etc. is a DSL. The Class Designer is another example.

A DSL is just a set of tools that (at least in theory) make development in a specific "domain" (i.e. visual layout) easier, more intuitive, and more productive.

As far as building a DSL, some of the stuff people like Ayende have written about is related to "text parsing" dsls, letting developers (or end users) enter "natural text" into an application, which parses the text and generates some sort of code or output based on it.

You could use any language to build your own DSL. Microsoft Visual Studio has a lot of extensibility points, and the patterns & practices "Guidance Automation Toolkit" and Visual Studio SDK can assist you in adding DSL functionality to Visual Studio.

Guy Starbuck
+2  A: 

DSL are basic compilers for custom languages. A good 'free and open' tool to develop them is available at ANTLR. Recently, I've been looking at this DSL for a state machine language use on a new project . I agree with Tim Howland above, that they can be a good way to let someone else customize your application.

kenny
+2  A: 

FYI, a book on DSLs is in the pipeline as part of Martin Fowler's signature series.

If its of the same standard as the other books in the series, it should be a good read.

More information here

toolkit