12

I am going to create an internal DSL for JVM. And I see that Scala and Groovy are the best candidates for this task. I found that Groovy script is less verbose, uses BigDecimal by default, while Scala has good type inference system. What are other differences between these languages in context of internal DSL?

EDIT: Finally I picked Groovy and after one year of development of the DSL it seems to be the right choice: I can benefit from type inference and static types in Groovy 2.0 and still use dynamic types when needed, methods/properties dispatch handlers work great, ASTTransforation allowed me to change the language semantics, groovy plugin for eclipse and IDEA have out of the box support for Groovy DSLs, and the DSL syntax is more concise than it would be in Scala. Though there are still some room for improvement as some dynamic features not always worked as I expected.

Nutel
  • 2,244
  • 2
  • 27
  • 50
  • 7
    Groovy and Scala are quite different things - beyond type inference, Scala actually has types, while Groovy is a dynamic scripting language. It would probably help a great deal to know what the application and goals are for your DSL. In general, though, I'd say use Scala over Groovy for almost any large application. – Janx Apr 30 '11 at 04:10
  • 4
    You can watch [interview with Debasish Ghosh](http://www.infoq.com/interviews/ghosh-dsls). It can be helpful for you. You may also be interested in his book [DSLs in Action](http://www.manning.com/ghosh/). – tenshi Apr 30 '11 at 14:12
  • @Easy thanks, it was quite helpful – Nutel May 01 '11 at 18:22
  • I **strongly** recommend DSLs in Action (www.manning.com/ghosh) by Debaish Ghosh. I read the Scala parts, which helped me immensely to get up to speed on DSLs. – Kevin Meredith Jan 14 '14 at 01:40

3 Answers3

5

I do not have experience with DSLs in Scala, but I can say that Groovy's dynamic nature via the meta object protocol makes it well-suited for DSLs. I found this series to be helpful when examining DSLs in Groovy. You probably also want to take a look at Martin Fowler's page, which includes a link to his book on the subject.

BennyFlint
  • 610
  • 6
  • 10
5

I have been working on a DSL for testing in Scala. I think that you'd end up writing more interpretation code in Scala (type conversions etc), but once you have there is no reason that your DSL should be more or less verbose. The payback is that (once IDEs catch up) you will have code completion to help write in your Scala DSL.

Scala pattern matching is also a huge win in writing the interpretation code.

Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
  • 1
    Really, a random downvote 18 months after this answer? WTF is going on in this place? – Duncan McGregor Dec 10 '12 at 12:23
  • And another. SO used to be a nice place – Duncan McGregor Aug 18 '13 at 20:48
  • Why did you choose an `internal` DSL over `external` (`parser combinators`)? [asking out of curiosity, not disagreement] – Kevin Meredith Jan 14 '14 at 01:39
  • Because I can get an internal DSL started in 20 minutes instead of 2 days learning enough parser combinator technique. Plus my IDE will play nice with an internal DSL – Duncan McGregor Jan 15 '14 at 06:43
  • I've only read about Internal DSLs with Scala in [DSLs in Action](http://www.manning.com/ghosh/). However, I've found Parser Combinators to be powerful and expressive. But, I've heard from a few Scala folks that [parboiled2](https://github.com/sirthias/parboiled2) is more appropriate for industrial usage. – Kevin Meredith Nov 30 '14 at 04:06
3

Lots of Groovy DSL goodness was added in 1.8.

Groovy is a good place to start.

Take a look at Gradle. Thats a build tool written in Groovy and the build language is a DSL.

Fortyrunner
  • 12,702
  • 4
  • 31
  • 54