Scala、Groovy、Clojure
有人可以解释一下 Scala、Groovy 和 Clojure 之间的主要区别吗?我知道这些编译结果都可以在 JVM 上运行,但我想对它们进行简单的比较。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Groovy 是一种动态类型语言,其语法非常接近 Java,并进行了许多语法改进,允许更轻的代码和更少的样板。它可以通过解释器运行并进行编译,这使得它非常适合快速原型设计、脚本和学习动态语言,而无需学习新语法(假设您了解 Java)。从 Groovy 2.0 开始,它对静态编译的支持也越来越多。 Groovy 支持闭包,并且支持以某种函数式风格进行编程,尽管它距离函数式编程的传统定义还很远。
Clojure 是 Lisp 的一种方言,具有一些高级功能,例如 软件事务内存。如果您喜欢 Lisp 并且想在 JVM 下使用类似的东西,那么 Clojure 适合您。它可能是在 JVM 上运行的最具功能性的语言,当然也是最著名的语言。此外,它比其他 Lisp 方言更加强调不变性,这使其更贴近核心函数式语言爱好者。
Scala 是一种完全面向对象的语言,比 Java 更先进,具有最先进的类型系统可用于非研究语言,当然也是 JVM 上最先进的类型系统。它还结合了函数式语言的许多概念和特性,而不损害面向对象,但它对函数式语言特性的妥协却让后者的一些爱好者望而却步。
Groovy 具有良好的接受度,并且是 Grails 中流行的 Web 框架。它还为 Gradle 构建系统提供支持,该系统正在成为 Maven 的流行替代品。我个人认为这是一种实用性有限的语言,特别是与其他语言相比,Jython 和 JRuby 开始进军 JVM 领域。
Clojure,即使不考虑一些非常有趣的功能,仅仅作为 JVM 上的 Lisp 方言就具有强大的吸引力。当然,它可能会限制它的受欢迎程度,但我预计它会在很长一段时间内拥有忠实的社区。
Scala 可以直接与 Java 竞争,几乎在所有方面都可以与 Java 竞争。当然,它目前在受欢迎程度方面无法与之竞争,而且缺乏强大的企业支持可能会阻碍其在企业环境中的接受度。从语言的发展方式来看,它也是一种比 Java 更具动态性的语言。从语言的角度来看,这是一件好事。从计划在其中编写数千行代码的用户的角度来看,事实并非如此。
最后声明一下,我非常熟悉 Scala,并且只熟悉其他两个。
Groovy is 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.
Clojure is 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 language running on the JVM, and certainly the most famous one. Also, it has a stronger emphasis on immutability than other Lisp dialects, which takes it closer to the heart of functional language enthusiasts.
Scala is a fully object oriented language, more so than Java, with one of the most advanced type systems available 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.
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.
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.
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.
As a final disclosure, I'm very familiar with Scala, and only acquainted with the other two.
Scala
Scala 是从一种名为 Funnel 的纯函数式语言发展而来,代表了几乎所有功能的洁净室实现。 Java 的语法,仅在可以进行明显改进或会损害语言功能性质的地方有所不同。这些差异包括单例对象而不是静态方法以及类型推断。
其中大部分内容基于 Martin Odersky 之前使用 Pizza 语言所做的工作。 OO/FP 集成远远超出了单纯的闭包,并且导致该语言被描述为后功能语言。
尽管如此,它在很多方面都最接近 Java。主要是因为 OO 支持和静态类型的结合,但也因为语言设计中的明确目标,即它应该与 Java 紧密集成。
Groovy
Groovy 通过动态类型化明确解决了 Java 的两个最大的批评
它可能在语法上最接近 Java,没有提供 Clojure 和 Scala 提供的一些更丰富的功能结构,但仍然提供了明确的进化改进 - 特别是对于编写脚本式程序。
Groovy 在这三种语言中拥有最强大的商业支持,主要是通过 springsource。
Clojure
Clojure 是 LISP 家族中的一种函数式语言,它也是动态类型的。
STM 支持等功能为其提供了一些最佳的开箱即用并发支持,而 Scala 则需要第 3 方库,例如 Akka 复制此内容。
从语法上来说,它也是三种语言中距离典型 Java 代码最远的。
我还必须透露我最熟悉 Scala :)
Scala
Scala evolved out of a pure functional language known as Funnel and 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.
Much of this was based on Martin Odersky's prior work with the Pizza language. The OO/FP integration goes far beyond mere closures and has led to the language being described as post-functional.
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.
Groovy
Groovy explicitly tackles two of Java's biggest criticisms by
It's perhaps syntactically closest 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.
Groovy has the strongest commercial backing of the three languages, mostly via springsource.
Clojure
Clojure is a functional language in the LISP family, it's also dynamically typed.
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 Akka to duplicate this.
Syntactically, it's also the furthest of the three languages from typical Java code.
I also have to disclose that I'm most acquainted with Scala :)
我从来没有时间玩 clojure。但对于 scala 与 groovy,这是 Groovy 创造者 James Strachan 的话
您可以阅读整个故事 此处
I never had time to play with clojure. But for scala vs groovy, this is words from James Strachan - Groovy creator
You can read the whole story here
它们可以根据来自哪里或主要针对哪些开发人员进行区分。
Groovy 有点像 Java 的脚本版本。长期的 Java 程序员在构建由大型架构支持的敏捷应用程序时感到宾至如归。顾名思义,Groovy on Grails 与 Rails 框架类似。对于那些不想一直为 Java 的冗长而烦恼的人来说。
Scala 是一种面向对象的函数式编程语言,Ruby 或 Python 程序员可能感觉更接近到这个。它采用了这些编程语言中的许多常见的好主意。
Clojure 是 Lisp 编程语言的一种方言,因此 Lisp、Scheme 或 Haskell 开发人员可能会感到宾至如归用这种语言进行开发。
They can be differentiated with where they are coming from or which developers they're targeting mainly.
Groovy is 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.
Scala is 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.
Clojure is a dialect of the Lisp programming language so Lisp, Scheme or Haskell developers may feel at home while developing with this language.
我正在阅读 Scott Davis 所著的 Pragmatic Programmers 书籍“Groovy Recipes: Greeasing thewheels of Java”,版权所有 2008,并于同年 4 月印刷。
它有点过时了,但是这本书清楚地表明 Groovy 实际上是 Java 的扩展。我可以编写功能与 Java 完全相同的 Java 代码,并将文件重命名为 *.groovy,它工作得很好。根据这本书,如果我包含必需的库,则相反。到目前为止,实验似乎证实了这一点。
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.
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 应用程序脚本,Scala 可能不是一个好的选择,因为并不容易方式从 Java 评估它,而 Groovy 特别适合这个目的。
Obviously, the syntax are completely different (Groovy is closest to Java), but I suppose that is not what you are asking for.
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 evaluate it from Java, whereas Groovy is especially suited for that purpose.