Why would I choose to use Groovy when I could use Jython or Jruby? Does the language provide any inherent advantages to make up for the fact that Jython and Jruby skills are applicable to their parent languages outside of the JVM?
当我可以使用Jython或Jruby时,为什么我会选择使用Groovy?该语言是否提供了任何固有的优势来弥补Jython和Jruby技能适用于JVM之外的其他语言的事实?
Keep in mind that I purposely keeping this question generic, but if there are any advantages that exist in a particular domain, please don't hesitate to describe them.
请记住,我故意将此问题保持为通用,但如果特定域中存在任何优势,请不要犹豫,对其进行描述。
EDIT
To clarify, If I write some code in Jruby, I can now, in some cases, move that code outside of the JVM if need be, or at the very least I have gained a better understanding of Ruby. Whereas Groovy skills are applicable only when using a language that just exists inside the JVM. Jython and Jruby have this built in advantage, what does Groovy have to make up for this disadvantage?
编辑为了澄清,如果我在Jruby中编写一些代码,在某些情况下,如果需要,我现在可以将代码移到JVM之外,或者至少我已经对Ruby有了更好的理解。而Groovy技能仅在使用JVM中存在的语言时才适用。 Jython和Jruby具有这种内置优势,Groovy必须弥补这一劣势吗?
If Groovy doesn't have any advantages that you've found, and you would suggest just using Jython or Jruby, let me know.
如果Groovy没有你找到的任何优势,你建议只使用Jython或Jruby,请告诉我。
Edit 2
Thanks everyone for all the answers, most of them make the same point, Groovy integrates slightly better with Java then Jython or Jruby.
编辑2感谢大家的所有答案,其中大多数都提出了相同的观点,Groovy与Java,Jython或Jruby集成得稍好一些。
Follow up
Using Netbeans 6.5 as my IDE I have found that Groovy to integrates better with Java projects then Jruby. I am not sure if lack of integration is a failing of Jruby or Netbeans. But after using it for alittle Groovy definitely seems to have a leg up.
跟进使用Netbeans 6.5作为我的IDE我发现Groovy可以更好地与Java项目集成,然后是Jruby。我不确定缺乏集成是否是Jruby或Netbeans的失败。但是在使用它之后,Groovy似乎肯定会有所帮助。
37
I've done pretty extensive development in Ruby and Groovy (as well as a little Jython using Grinder as a load testing tool).
我已经在Ruby和Groovy中进行了相当广泛的开发(以及使用Grinder作为负载测试工具的一点Jython)。
Of the 3, I prefer Groovy the most. I like the closure syntax the best and I think that it has the tightest integration in how it works with other java classes on the JVM. It's been a little while since I last used JRuby, but importing Java classes and working with the classloader in JRuby didn't feel as clean to me.
在3中,我最喜欢Groovy。我最喜欢闭包语法,我认为它与JVM上其他java类的工作方式有最紧密的集成。自从我上次使用JRuby以来已经有一段时间了,但导入Java类并使用JRuby中的类加载器对我来说并不是那么干净。
The fact that Groovy is also essentially a superset of Java means that the huge population of Java programmers out there will have a quicker uptake time in picking Groovy up over Ruby/JRuby. They can start programming it like it's Java and slowly start inserting idomatic groovy as they pick it up.
事实上,Groovy本质上也是Java的超集,这意味着大量的Java程序员可以更快地在Ruby / JRuby上选择Groovy。他们可以像Java一样开始编程,然后慢慢开始插入idomatic groovy。
More to the point of what you're asking, I think that another advantage of Groovy is that the language that you go to when you want to optimize something is almost the exact same syntax, it's Java. If you're working in the Ruby or Python worlds, you're going to have to go to either C which is a big shift or Java, which is also quite different than those languages. Programming in Groovy tends to help keep your Java skills somewhat sharp as well.
更多的是你要问的问题,我认为Groovy的另一个优点是,当你想要优化某些东西时,你所使用的语言几乎是完全相同的语法,它是Java。如果您在Ruby或Python世界中工作,那么您将不得不去C大转移或Java,这也与那些语言完全不同。 Groovy中的编程往往有助于保持Java技能的某些程度。
If you have particular access to a Ruby or Python infrastructure, or a team that has familiarity with those kind of environments, then I could see choosing one of those other languages.
如果您可以访问Ruby或Python基础结构,或者熟悉这种环境的团队,那么我可以看到选择其他语言之一。
Really, all 3 of them are very nice languages and what you pick should depend more on the problem that you're trying to fix and the resources that you have available to you. Once you've become proficient in one dynamic language, picking up a second or a third is much easier.
实际上,它们中的3个都是非常好的语言,您选择的内容应该更多地取决于您尝试修复的问题以及您可以使用的资源。一旦掌握了一种动态语言,就可以轻松获得第二种或第三种语言。
13
I would say if you need to mix Java with Jruby/Groovy, go with Groovy. As everybody said, Groovy has tighter Java integration.
我想说如果你需要将Java与Jruby / Groovy混合使用,请使用Groovy。正如大家所说,Groovy拥有更紧密的Java集成。
But as far as the language implementation goes, I prefer the Ruby language over Groovy, the language revolves around itself, in Groovy there are some hacks that are inherent to the implementation itself (just watch a Grails stacktrace vs. a Rails stacktrace and you'll see what I mean).
但就语言实现而言,我更喜欢Ruby语言而不是Groovy,语言围绕着自身,在Groovy中有一些实现本身固有的hacks(只是观看Grails栈跟踪而不是Rails栈跟踪而你'我明白我的意思了。
I highly recommend seeing Neal Ford's comparison of Groovy and JRuby
我强烈建议看看Neal Ford对Groovy和JRuby的比较
3
I think Dick Wall gave a very good summary of the differences between these three on the Java Posse podcast (#213, about 34:20 in) ... "JRuby was designed to make programmers happy ... it's a programming language developer's choice; Python has very strong roots in simplicity and education; Groovy is aimed squarely at being the choice for Java developers ... it's a very familiar environment for Java ... with support for annotations".
我认为Dick Wall在Java Posse播客(#213,大约34:20 in)中给出了这三者之间差异的非常好的总结......“JRuby旨在让程序员高兴...这是编程语言开发人员的选择; Python在简单性和教育方面有着非常强大的根基; Groovy的目标是成为Java开发人员的选择......这是一个非常熟悉的Java环境......支持注释“。
In terms of moving the language outside of the JVM, I don't think the Java runtime imposes much of an overhead -- it's a simple install, and you need to set some environment variables -- but it does provide a number of benefits including a mature runtime which has been highly optimised, and a large set of libraries. The JRuby team are now reporting better performance than the native MRI. http://blog.headius.com/2008/08/twas-brillig.html
关于在JVM之外移动语言,我不认为Java运行时会产生很大的开销 - 这是一个简单的安装,你需要设置一些环境变量 - 但它确实提供了许多好处,包括一个经过高度优化的成熟运行时,以及一大堆库。 JRuby团队现在报告的性能优于原生MRI。 http://blog.headius.com/2008/08/twas-brillig.html
1
I've only had experience with Jython and Groovy. The biggest disadvantage with Jython, at the moment, is that the latest release recommended for production (2.2.1) has a feature set that "roughly corresponds to that of Python-2.2" (Jython FAQ). There is a beta implementing what I assume is Python 2.5, which is now a version behind. Don't know if the same can be said for JRuby.
我只有Jython和Groovy的经验。目前,Jython的最大缺点是推荐用于生产的最新版本(2.2.1)具有“大致对应于Python-2.2”的功能集(Jython FAQ)。有一个测试版实现了我认为的Python 2.5,它现在是一个版本。不知道JRuby是否可以这么说。
0
I don't know why you should choose Groovy because I don't know your background. If you are a Java developer Groovy feels more similar to your current language then JRuby or Jython. Groovy combines the best of Java, the language, Java, the platform, and Ruby the language.
我不知道为什么你应该选择Groovy,因为我不知道你的背景。如果您是Java开发人员,那么Groovy会更像您当前的语言,而不是JRuby或Jython。 Groovy结合了最好的Java,语言,Java,平台和Ruby语言。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2008/11/13/85fef05ced05e26f515458cb1af9511c.html。