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.
DSL or Domain specific language is meant to simplify the code written in Groovy in such a way that it becomes easily understandable for the common user. The following example shows what exactly is meant by having a domain specific language.
What is a DSL? There is a larger definition of a domain specific language, however in the context of Groovy code, a DSL is a way of creating APIs that leverages Groovy's closures to create an easy way to build complex data. To understand how a DSL works, you must understand how closures work.
Introduction to DRL/DSL It is a set commands which are used to retrieve data from database server. It manipulates the data in database for display purpose like aggregate function. In DRL/DSL, for accessing the data it uses the DML command that is SELECT.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With