Groovy 相对于 Jython 或 Jruby 的优势?

发布于 2024-07-08 16:33:41 字数 675 浏览 7 评论 0 原文

当我可以使用 Jython 或 Jruby 时,为什么我要选择使用 Groovy? 该语言是否提供了任何固有的优势来弥补 Jython 和 Jruby 技能适用于 JVM 之外的其父语言的事实?

请记住,我故意保持这个问题的通用性,但如果特定领域存在任何优势,请毫不犹豫地描述它们。

编辑
澄清一下,如果我在 Jruby 中编写一些代码,在某些情况下,我现在可以根据需要将该代码移出 JVM,或者至少我对 Ruby 有了更好的了解。 而 Groovy 技能仅在使用 JVM 内存在的语言时才适用。 Jython 和 Jruby 有这个内置的优势,Groovy 需要用什么来弥补这个劣势呢?

如果 Groovy 没有您发现的任何优点,并且您建议只使用 Jython 或 Jruby,请告诉我。

编辑2
感谢大家的所有回答,他们中的大多数都提出了相同的观点,Groovy 与 Java 的集成略好于 Jython 或 Jruby。

跟进
使用 Netbeans 6.5 作为我的 IDE,我发现 Groovy 与 Java 项目的集成比 Jruby 更好。 我不确定缺乏集成是否是 Jruby 或 Netbeans 的失败。 但在使用了一点之后,Groovy 似乎确实有优势。

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?

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?

If Groovy doesn't have any advantages that you've found, and you would suggest just using Jython or Jruby, let me know.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

卷耳 2024-07-15 16:33:41

我在 Ruby 和 Groovy 中进行了相当广泛的开发(以及使用 Grinder 作为负载测试工具的一点 Jython)。

在这 3 个中,我最喜欢 Groovy。 我最喜欢闭包语法,并且我认为它在与 JVM 上的其他 java 类一起工作方面具有最紧密的集成。 自从我上次使用 JRuby 以来已经有一段时间了,但是导入 Java 类并使用 JRuby 中的类加载器对我来说并不那么干净。

事实上,Groovy 本质上也是 Java 的超集,这意味着大量 Java 程序员会比 Ruby/JRuby 更快地掌握 Groovy。 他们可以开始像 Java 一样对其进行编程,并在拿起它时慢慢开始插入 idomatic groovy。

更重要的是你所问的问题,我认为 Groovy 的另一个优点是,当你想要优化某些东西时,你使用的语言几乎是完全相同的语法,它是 Java。 如果您在 Ruby 或 Python 领域工作,那么您将不得不使用 C(这是一个重大转变)或 Java(与这些语言也有很大不同)。 使用 Groovy 编程也有助于保持 Java 技能的敏锐度。

如果您对 Ruby 或 Python 基础设施有特殊的访问权限,或者团队熟悉这些环境,那么我可以考虑选择其他语言之一。

确实,这三种语言都是非常好的语言,您选择什么应该更多地取决于您要解决的问题以及您可以使用的资源。 一旦您精通一种动态语言,学习第二种或第三种就会容易得多。

I've done pretty extensive development in Ruby and Groovy (as well as a little Jython using Grinder as a load testing tool).

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.

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.

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.

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.

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.

卖梦商人 2024-07-15 16:33:41

我想说,如果您需要将 Java 与 Jruby/Groovy 混合使用,请选择 Groovy。 正如大家所说,Groovy 具有更紧密的 Java 集成。

但就语言实现而言,我更喜欢 Ruby 语言而不是 Groovy,该语言围绕其自身旋转,在 Groovy 中存在一些实现本身固有的技巧(只需观看 Grails 堆栈跟踪与 Rails 堆栈跟踪,您就会明白我的意思)。

强烈推荐查看 Neal Ford 的Groovy 和 JRuby 的比较< /a>

I would say if you need to mix Java with Jruby/Groovy, go with Groovy. As everybody said, Groovy has tighter Java integration.

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).

I highly recommend seeing Neal Ford's comparison of Groovy and JRuby

原谅我要高飞 2024-07-15 16:33:41

我认为 Dick Wall 在 Java Posse 播客(#213,大约 34:20 中)上很好地总结了这三者之间的差异...
“JRuby 的设计初衷是让程序员感到高兴……它是开发人员的一种编程语言;Python 在简单性和教育方面具有很强的根基;Groovy 的目标是成为 Java 开发人员的选择……这是 Java 非常熟悉的环境。 ..支持注释”。

就将语言移出 JVM 而言,我认为 Java 运行时不会带来太多开销——安装很简单,并且需要设置一些环境变量——但它确实提供了许多好处,包括一个经过高度优化的成熟运行时,以及大量的库。 JRuby 团队现在报告的性能比本机 MRI 更好。 http://blog.headius.com/2008/08/twas-brillig。 html

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".

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

无言温柔 2024-07-15 16:33:41

我只使用过 Jython 和 Groovy。 目前,Jython 的最大缺点是推荐用于生产的最新版本 (2.2.1) 具有“大致对应于 Python-2.2 的功能集”(Jython 常见问题解答)。 有一个测试版实现了我认为的 Python 2.5,但现在版本落后了。 不知道 JRuby 是否也是如此。

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.

裂开嘴轻声笑有多痛 2024-07-15 16:33:41

我不知道为什么应该选择 Groovy,因为我不了解你的背景。 如果您是 Java 开发人员,Groovy 感觉与您当前使用的语言更相似,然后是 JRuby 或 Jython。 Groovy 结合了 Java 语言、Java 平台和 Ruby 语言的优点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文