Scala 与 Groovy 与 Clojure
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1314732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scala vs. Groovy vs. Clojure
提问by James Fassett
Can someone please explain the major differences between Scala, Groovy and Clojure. I know each of these compiles to run on the JVM but I'd like a simple comparison between them.
有人能解释一下 Scala、Groovy 和 Clojure 之间的主要区别吗?我知道这些编译中的每一个都可以在 JVM 上运行,但我想对它们进行简单的比较。
回答by Daniel C. Sobral
Groovyis a dynamically typed language, whose syntax is very close to Java, with a number of syntax improvements that allow for lighter code and less boilerplate. It can run through an interpreter as well as being compiled, which makes it good for fast prototyping, scripts, and learning dynamic languages without having to learn a new syntax (assuming you know Java). As of Groovy 2.0, it also has growing support for static compilation. Groovy supports closures and has support for programming in a somewhat functional style, although it's still fairly far from the traditional definition of functional programming.
Groovy是一种动态类型语言,其语法与 Java 非常接近,并进行了许多语法改进,可实现更轻量的代码和更少的样板。它可以通过解释器运行,也可以被编译,这使得它非常适合快速原型设计、脚本和学习动态语言,而无需学习新语法(假设您了解 Java)。从 Groovy 2.0 开始,它也越来越支持静态编译。Groovy 支持闭包并支持以某种函数式风格进行编程,尽管它与函数式编程的传统定义相距甚远。
Clojureis a dialect of Lisp with a few advanced features like Software Transactional Memory. If you like Lisp and would like to use something like it under the JVM, Clojure is for you. It's possibly the most functional languagerunning on the JVM, and certainly the most famous one. Also, it has a stronger emphasis on immutabilitythan other Lisp dialects, which takes it closer to the heart of functional language enthusiasts.
Clojure是 Lisp 的一种方言,具有一些高级功能,例如Software Transactional Memory。如果您喜欢 Lisp 并想在 JVM 下使用类似的东西,Clojure 适合您。它可能是在 JVM 上运行的最实用的语言,当然也是最著名的语言。此外,它比其他 Lisp 方言更强调不变性,这使它更接近函数式语言爱好者的心。
Scalais a fully object oriented language, more so than Java, with one of the most advanced type systemsavailable on non-research languages, and certainly the most advanced type system on the JVM. It also combines many concepts and features of functional languages, without compromising the object orientation, but its compromise on functional language characteristics put off some enthusiasts of the latter.
斯卡拉是一个完全面向对象的语言,比Java更何况,用最先进的一个类型系统对非研究语言的版本,当然在JVM上最先进的类型系统。它还结合了函数式语言的许多概念和特性,在不影响面向对象的情况下,但它对函数式语言特性的妥协让后者的一些爱好者望而却步。
Groovy has good acceptance and a popular web framework in Grails. It also powers the Gradle build system, which is becoming a popular alternative to Maven. I personally think it is a language with limited utility, particularly as Jython and JRuby start making inroads on the JVM-land, compared to the others.
Groovy 在 Grails 中具有良好的接受度和流行的 Web 框架。它还支持 Gradle 构建系统,该系统正成为 Maven 的流行替代品。我个人认为它是一种实用性有限的语言,特别是当 Jython 和 JRuby 开始在 JVM 领域取得进展时,与其他语言相比。
Clojure, even discounting some very interesting features, has a strong appeal just by being a Lisp dialect on JVM. It might limit its popularity, granted, but I expect it will have loyal community around it for a long time.
Clojure 甚至不考虑一些非常有趣的功能,仅作为 JVM 上的 Lisp 方言就具有很强的吸引力。它可能会限制它的受欢迎程度,当然,但我希望它会在很长一段时间内拥有忠实的社区。
Scala can compete directly with Java, and give it a run for its money on almost all aspects. It can't compete in popularity at the moment, of course, and the lack of a strong corporate backing may hinder its acceptance on corporate environments. It's also a much more dynamic language than Java, in the sense of how the language evolves. From the perspective of the language, that's a good thing. From the perspective of users who plan on having thousands of lines of code written in it, not so.
Scala 可以直接与 Java 竞争,并在几乎所有方面与 Java 竞争。当然,目前它无法在受欢迎程度上与之竞争,而且缺乏强大的企业支持可能会阻碍其在企业环境中的接受度。就语言如何演变而言,它也是一种比 Java 更具动态性的语言。从语言的角度来看,这是一件好事。从计划在其中编写数千行代码的用户的角度来看,并非如此。
As a final disclosure, I'm very familiar with Scala, and only acquainted with the other two.
作为最后的披露,我对 Scala 非常熟悉,只熟悉其他两个。
回答by Kevin Wright
Scala
斯卡拉
Scala evolved out of a pure functional language known as Funneland represents a clean-room implementation of almost all Java's syntax, differing only where a clear improvement could be made or where it would compromise the functional nature of the language. Such differences include singleton objects instead of static methods, and type inference.
Scala 是从一种称为Funnel的纯函数式语言演变而来的,它代表了几乎所有 Java 语法的洁净室实现,不同之处仅在于可以进行明显改进的地方或会损害语言的函数性质的地方。这些差异包括单例对象而不是静态方法和类型推断。
Much of this was based on Martin Odersky's prior work with the Pizzalanguage. The OO/FP integration goes far beyond mere closures and has led to the language being described as post-functional.
其中大部分是基于 Martin Odersky 之前在Pizza语言方面的工作。OO/FP 集成远远超出了单纯的闭包,并导致语言被描述为后功能。
Despite this, it's the closest to Java in many ways. Mainly due to a combination of OO support and static typing, but also due to a explicit goal in the language design that it should integrate very tightly with Java.
尽管如此,它在许多方面最接近 Java。主要是由于 OO 支持和静态类型的组合,但也由于语言设计中的一个明确目标,即它应该与 Java 非常紧密地集成。
Groovy
常规
Groovy explicitly tackles two of Java's biggest criticisms by
Groovy 明确地解决了 Java 的两个最大的批评
- being dynamically typed, which removes a lot of boilerplate and
- adding closures to the language.
- 被动态输入,删除了大量的样板文件和
- 为语言添加闭包。
It's perhaps syntacticallyclosest to Java, not offering some of the richer functional constructs that Clojure and Scala provide, but still offering a definite evolutionary improvement - especially for writing script-syle programs.
它可能在语法上最接近 Java,没有提供 Clojure 和 Scala 提供的一些更丰富的功能结构,但仍然提供了明确的进化改进——尤其是对于编写脚本风格的程序。
Groovy has the strongest commercial backing of the three languages, mostly via springsource.
Groovy 在这三种语言中拥有最强大的商业支持,主要是通过 springsource。
Clojure
Clojure
Clojure is a functional language in the LISP family, it's also dynamically typed.
Clojure 是 LISP 家族中的一种函数式语言,它也是动态类型的。
Features such as STM support give it some of the best out-of-the-box concurrency support, whereas Scala requires a 3rd-party library such as Akkato duplicate this.
STM 支持等特性为其提供了一些最好的开箱即用的并发支持,而 Scala 需要像Akka这样的 3rd-party 库来复制它。
Syntactically, it's also the furthest of the three languages from typical Java code.
在语法上,它也是三种语言中距离典型 Java 代码最远的一种。
I also have to disclose that I'm most acquainted with Scala :)
我还必须透露,我最熟悉 Scala :)
回答by Thai Tran
I never had time to play with clojure. But for scala vs groovy, this is words from James Strachan - Groovy creator
我从来没有时间玩 clojure。但是对于 scala 与 groovy,这是来自 James Strachan - Groovy 的创造者的话
"Though my tip though for the long term replacement of javac is Scala. I'm very impressed with it! I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy."
“虽然我对长期替代 javac 的建议是 Scala。我对它印象非常深刻!老实说,如果有人在 2003 年向我展示了 Martin Odersky、Lex Spoon 和 Bill Venners 合着的 Programming in Scala 一书,我'可能永远不会创建 Groovy。”
You can read the whole story here
你可以在这里阅读整个故事
回答by Mehmet Duran
They can be differentiated with where they are coming from or which developers they're targeting mainly.
它们可以根据它们的来源或主要针对哪些开发人员来区分。
Groovyis a bit like scripting version of Java. Long time Java programmers feel at home when building agile applications backed by big architectures. Groovy on Grails is, as the name suggests similar to the Rails framework. For people who don't want to bother with Java's verbosity all the time.
Groovy有点像 Java 的脚本版本。长期以来,Java 程序员在构建由大型架构支持的敏捷应用程序时都会感到宾至如归。顾名思义,Grails 上的 Groovy 类似于 Rails 框架。对于那些不想一直为 Java 的冗长而烦恼的人。
Scalais an object oriented and functional programming language and Ruby or Python programmers may feel more closer to this one. It employs quite a lot of common good ideas found in these programming languages.
Scala是一种面向对象的函数式编程语言,Ruby 或 Python 程序员可能更接近于这一点。它采用了很多在这些编程语言中常见的好想法。
Clojureis a dialect of the Lisp programming language so Lisp, Scheme or Haskell developers may feel at home while developing with this language.
Clojure是 Lisp 编程语言的一种方言,因此 Lisp、Scheme 或 Haskell 开发人员在使用这种语言进行开发时可能会感到宾至如归。
回答by Jim Collings
I'm reading the Pragmatic Programmers book "Groovy Recipes: Greasing the wheels of Java" by Scott Davis, Copyright 2008 and printed in April of the same year.
我正在阅读 Scott Davis 所著的 Pragmatic Programmers 书籍“Groovy Recipes: Greasing the Wheels of Java”,版权所有 2008,同年 4 月出版。
It's a bit out of date but the book makes it clear that Groovy is literally an extension of Java. I can write Java code that functions exactly like Java and rename the file *.groovy and it works fine. According to the book, the reverse is true if I include the requisite libraries. So far, experimentation seems to bear this out.
这有点过时了,但是这本书清楚地表明 Groovy 实际上是 Java 的扩展。我可以编写功能与 Java 完全相同的 Java 代码,并将文件重命名为 *.groovy,它工作正常。根据这本书,如果我包括必需的库,则相反。到目前为止,实验似乎证实了这一点。
回答by Thilo
Obviously, the syntax are completely different (Groovy is closest to Java), but I suppose that is not what you are asking for.
显然,语法完全不同(Groovy 最接近 Java),但我想这不是您所要求的。
If you are interested in using them to script a Java application, Scala is probably not a good choice, as there is no easy way to evaluateit from Java, whereas Groovy is especially suited for that purpose.
如果您有兴趣使用它们编写 Java 应用程序脚本,Scala 可能不是一个好的选择,因为没有简单的方法可以从 Java评估它,而 Groovy 尤其适合这个目的。

