• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic vs. DSL

 
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Terrence,
How does one decide whether to build a Domain Specific Language and when to go the General Programming Language route? While I don't know, I suspect that some domains may be large or complex enough that a DSL for them might border on being a GPL. So I guess I'm wondering where you draw the line - if there is one.

Thanks,
Burk
 
author
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hiya. I kind of responded to this topic in another post, but let me repeat that I tend to build a DSL when I have to do the same bit of general-purpose programming again and again. Or, sometimes the pain will be so much that I start by building a DSL or tool.

Yep, SQL is a DSL because its domain specific, but it's bigger than many general-purpose programming languages. So implementing SQL would be a huge undertaking. I'd stick with a general-purpose programming language instead of implementing SQL. ;) Thankfully, somebody has already implemented it for us on the various database platforms.
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Terence Parr wrote:... let me repeat that I tend to build a DSL when I have to do the same bit of general-purpose programming again and again.



Terrance,
Thanks for the reply. I think I'm a little confused though. To me "the same bit of general-purpose programming" sounds more like a reason to create a library or API, not a language. Are there some critical differentiators?

Thanks,
Burk
 
Terence Parr
author
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Burk Hufnagel wrote:I think I'm a little confused though. To me "the same bit of general-purpose programming" sounds more like a reason to create a library or API, not a language. Are there some critical differentiators?



Oh, right. good followup. DSLs are like libraries with a different interface. Libraries help a great deal and are a great way to start; you can think of them as factoring out common functionality for reuse by yourself and others just like a DSL. The difference is that sometimes the syntax of your library (method calls etc) is not as readable as a syntax specific to a domain. For example, you can create mathematics libraries but sometimes it's better to use math specific DSL is like Mathematica or Matlab.
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Terrence,
I think I'm getting the hang of this. So if I create a pizza builder class that has a "humane" interface and lets you order a pizza like this:
Pizza myPizza = PizzaBuilder.makeA(LARGE).pizza().with(THIN_CRUST).and().with(PEPPERONI).and().with(EXTRA_CHEESE);
I've actually created a DSL for placing a pizza order.

Am I on the right track or way out in left-field?

Burk
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Burk Hufnagel wrote:Terrence,So if I create a pizza builder class that has a "humane" interface and lets you order a pizza like this:
Pizza myPizza = PizzaBuilder.makeA(LARGE).pizza().with(THIN_CRUST).and().with(PEPPERONI).and().with(EXTRA_CHEESE);
I've actually created a DSL for placing a pizza order.


Yes, an internal DSL. And I might come up with a non-internal DSL to be used like so:
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am getting a feel for DSL through the discussions since yesterday. If i am getting it right DSLs are more about the idea of kernel application with pluggable utilities/services. Is this a limiting view?

Further, aren't DSLs a huge undertaking in terms of maintainability and usability?

thanks,
-Neha
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nehaa arora wrote:If i am getting it right DSLs are more about the idea of kernel application with pluggable utilities/services. Is this a limiting view?

Further, aren't DSLs a huge undertaking in terms of maintainability and usability?



Nehaa,

I think creating applications that support pluggable utilities/services are anything but limiting - you're allowing people to add new capabilities without modifying the basic application - just like Eclipes and NetBeans. Look at all the capabilities these platforms have because they support plugins.

As for the cost, I suspect that it's similar to the cost of creating your own API or library and that depends on how well you design and write the underlying code.

Burk
 
nehaa arora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Burk,

I share your view on the plus of pluggable application framework. I intended to use 'limiting' in my question to mean if i am viewing the DSL application domain, wholly or just an aspect (ie. creating application architectures that support pluggability).

 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nehaa arora wrote:Burk,

I share your view on the plus of pluggable application framework. I intended to use 'limiting' in my question to mean if i am viewing the DSL application domain, wholly or just an aspect (ie. creating application architectures that support pluggability).



Nehaa,
If you consider things like XML, regular expressions, CSS, and ant as DSLs then I believe that what we've been talking about is definitely a small aspect of the whole.
Burk
 
nehaa arora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Burk, that sounds quite right

thanks,
Neha
 
Terence Parr
author
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Burk Hufnagel wrote:So if I create a pizza builder class that has a "humane" interface and lets you order a pizza like this:
Pizza myPizza = PizzaBuilder.makeA(LARGE).pizza().with(THIN_CRUST).and().with(PEPPERONI).and().with(EXTRA_CHEESE);
I've actually created a DSL for placing a pizza order.



Some may disagree, but I don't think that's a DSL. it looks like Java to me with a nice API. That's a good idea, but not a DSL. Otherwise, all of my code would be in a multiple DSLs. ;) Your 2nd example has a DSL in the string: "+pepperoni +triplecheese" etc...

Internal DSL to me is one where you create NEW syntax but within the existing framework of the programming language. 'course that ain't my term. It's Fowlers'. I should probably go read his def again.
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Terence Parr wrote:Some may disagree, but I don't think that's a DSL. it looks like Java to me with a nice API. That's a good idea, but not a DSL. Otherwise, all of my code would be in a multiple DSLs. ;) Your 2nd example has a DSL in the string: "+pepperoni +triplecheese" etc...

Internal DSL to me is one where you create NEW syntax but within the existing framework of the programming language. 'course that ain't my term. It's Fowlers'. I should probably go read his def again.



Dang. I thought I was getting the hang of it. So are you saying that when creating a DSL in Java we need to pass one or more Strings to an interpreter/renderer so that we're not using the Java syntax?

BTW, that second example was Lasse's -- good job Lasse!

Burk
 
Ranch Hand
Posts: 35
Android VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dang. I thought I was getting the hang of it. So are you saying that when creating a DSL in Java we need to pass one or more Strings to an interpreter/renderer so that we're not using the Java syntax?



sorry to interrupt. But if that is the case then I was in wrong impression about DSL. I was thinking internal languages of companies as DSL.
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dhaval yoganandisorry to interrupt. But if that is the case then I was in wrong impression about DSL. I was thinking internal languages of companies as DSL. [/quote wrote:

That may still be true.

 
Terence Parr
author
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Burk Hufnagel wrote:Dang. I thought I was getting the hang of it. So are you saying that when creating a DSL in Java we need to pass one or more Strings to an interpreter/renderer so that we're not using the Java syntax?



Ok, I just read Martin Fowler's internal DSL definition again. I believe we are in agreement. He says, "Internal DSLs are limited by the syntax and structure of your base language." SO, they are still valid programs in, say, Java or Ruby but you're trying to make it look like another language (a DSL). Ruby lets you do this easily; see Ruby on Rails. Java not so much. You can say "a.add(b)" for but ruby lets you say "a + b" for some weird types like 3D vectors for a game language. In C/C++, the preprocessor lets you do some fun stuff like:

[code]
TURN_LEFT;
TURN_LEFT;
SHOOT_LASER(FORWARD);
[code]

Technically, that's not C though. The C compiler only sees the result of running the macro preprocessor on that.

Internal DSLs are the quickest way to get rolling since you are really just building a library, which you do everyday. When the syntax of the implementation language restricts the expressiveness of your DSL too much, time to build an external DSL. When you need to build a parser, you truly have an external DSL on your hands.

Look at it this way. Internal DSLs are just proper subsets of a programming language so your creativity is constrained and, of course, nonprogrammers can't use them. Internal DSLs *are* libraries so I think of them as that. But, I'm biased towards inflexible languages like Java. In Ruby, I could make function calls that don't look like calls. This let's me create Ruby programs that don't look like what I read in the tutorials...a negative in my view, btw.

Just to confuse you, the char within a string can be anything you want so you can put SQL or StringTemplate or whatever you want in there. The same string can live comfortably in python, C, ruby, SNOBOL, Java, C# etc... To execute that string, you need to implement a parser and an interpreter or translator.
 
Terence Parr
author
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dhaval yoganandi wrote:I was thinking internal languages of companies as DSL.



By internal, Martin Fowler means written with in the constraints of another language. More like a library than new syntax.
 
dhaval yoganandi
Ranch Hand
Posts: 35
Android VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Terence Parr wrote:

dhaval yoganandi wrote:I was thinking internal languages of companies as DSL.



By internal, Martin Fowler means written with in the constraints of another language. More like a library than new syntax.



If its library kind of thing. Then I was in wrong impression about DSL. I was talking about the internal language implemented by using the custom parser/interpreter. Thanks Mr. Terence for info.
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Terence Parr wrote:Ok, I just read Martin Fowler's internal DSL definition again. I believe we are in agreement. He says, "Internal DSLs are limited by the syntax and structure of your base language." SO, they are still valid programs in, say, Java or Ruby but you're trying to make it look like another language (a DSL).

<snip>

Look at it this way. Internal DSLs are just proper subsets of a programming language so your creativity is constrained and, of course, nonprogrammers can't use them. Internal DSLs *are* libraries so I think of them as that. But, I'm biased towards inflexible languages like Java. In Ruby, I could make function calls that don't look like calls. This let's me create Ruby programs that don't look like what I read in the tutorials...a negative in my view, btw.



So then my pizza example would be considered a valid internal DSL - right?
 
Terence Parr
author
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Burk Hufnagel wrote:So then my pizza example would be considered a valid internal DSL - right?





Would probably count as an internal DSL as it reads pretty well as a pizza language, despite being in Java. Smalltalk for example could do a little bit better:



That is definitely an internal DSL so I guess the Java version is too. If you modified the library so it didn't read so well, it would probably tiptoe over the blurry line into just an API; check this out:



The and() and with() methods here are the key distinguishing element between an internal DSL and just an API. Heh, maybe we should write that down somewhere. oh, we just did! thanks for the example, Burk!
 
Burk Hufnagel
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Considering you did all the work, you're very welcome.

Actually, I think it makes a nice example.

Thank you!
 
reply
    Bookmark Topic Watch Topic
  • New Topic