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 开发者_Python百科would be in Scala. Though there are still some room for improvement as some dynamic features not always worked as I expected.
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.
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.
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.
精彩评论