Groovy 与 Scala 的内部 DSL
我将为 JVM 创建一个内部 DSL。我认为 Scala 和 Groovy 是完成这项任务的最佳人选。我发现 Groovy 脚本不太冗长,默认使用 BigDecimal,而 Scala 具有良好的类型推断系统。在内部 DSL 上下文中,这些语言之间还有哪些其他区别?
编辑:最后我选择了 Groovy,经过一年的 DSL 开发,它似乎是正确的选择:我可以从 Groovy 2.0 中的类型推断和静态类型中受益,并且在需要时仍然使用动态类型,方法/属性调度处理程序工作得很好,ASTTransforation 允许我更改语言语义,Eclipse 和 IDEA 的 groovy 插件对 Groovy DSL 具有开箱即用的支持,并且 DSL 语法更比 Scala 更简洁。尽管仍有一些改进的空间,因为一些动态功能并不总是像我预期的那样工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我没有 Scala 中 DSL 的经验,但我可以说 Groovy 通过元对象协议实现的动态特性使其非常适合 DSL。我发现本系列在检查 DSL 时很有帮助好极了。您可能还想查看 Martin Fowler 的页面,其中包含指向他有关该主题的书籍的链接。
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.
我一直致力于在 Scala 中进行 DSL 测试。我认为您最终会在 Scala 中编写更多的解释代码(类型转换等),但是一旦您编写了这些代码,您的 DSL 就没有理由应该或多或少地冗长了。回报是(一旦 IDE 赶上)您将拥有代码补全功能来帮助编写 Scala DSL。
Scala 模式匹配在编写解释代码方面也是一个巨大的胜利。
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.
添加了许多 Groovy DSL 优点在 1.8 中。
Groovy 是一个很好的起点。
看看 Gradle。这是一个用 Groovy 编写的构建工具,构建语言是 DSL。
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.