您的位置: 新闻频道 Ruby新闻

原创新闻 Martin Flower分析Groovy和JRuby的前景

2007-12-09 by 见习编辑 robbin
评论(12) 有3667人浏览 groovy jruby
Martin Flower最近在自己的网站上面写了一篇分析Groovy和JRuby前景的文章:

http://martinfowler.com/bliki/GroovyOrJRuby.html

Groovy和JRuby是两个目前在JVM平台上面关注程度非常高的动态脚本语言,他们都比较适合用来做为领域专用语言(DSL)嵌入Java企业应用当中。而且目前Groovy和JRuby的发展都相当迅速,社区也比较健康。最近Groovy发布了1.5版本,而JRuby据评测性能已经超过了原生Ruby解析器。

作为Java平台的开发人员,特别是非常关注JVM平台动态脚本语言未来的人,当然非常好奇,究竟Groovy还是JRuby才是真命天子呢?那么让我们看看Martin是怎么看这个问题的:

首先Martin分析了Groovy和JRuby的共同点:

Martin Fowler 写道
Both JRuby and Groovy (and indeed Jython) are modern OO scripting languages. They combine the well-chosen terseness of scripting languages with good solid structures for building larger programs. As such they are suitable both for classical scripting and for writing larger programs. Both are comfortable with dynamic type checking, although Groovy does offer some static facilities too. Both support Closures which are an important feature for the greater expressiveness that people want from this kind of language.


JRuby和Groovy都是现代动态脚本语言,他们都适合构造结构良好坚固的大型应用。他们既可以用来写小型脚本应用,也适合构造大型应用。他们都具备了动态类型检查、闭包等先进的语法结构。

接着Martin比较了他们的区别:

引用
The biggest difference between them is their broader platform philosophy. Groovy is designed to be a scripting language for Java. As much as possible its syntax tries to match the equivalent in Java. ...... It also works with Java's class library directly.......

JRuby, however, is a Java implementation of the Ruby platform. Ruby can run directly on mainstream operating systems with a C runtime, and is starting to run on .NET's CLR. When you program in JRuby you primarily use Ruby's libraries which are implemented in Java, and may also use Java's libraries at your discretion. If you stick to Ruby's libraries, or at least wrap any foreign elements, you can run Ruby programs on the C, Java, or (in time) .NET runtimes. So you can use JRuby to both run Ruby programs on the JVM and as a language for scripting the JVM.


他们最大区别在于平台策略:Groovy尽量和Java保持一致性,不提供自己的类库,直接使用Java类库,而JRuby目标在跨多个运行平台的一致性,能够运行在操作系统Ruby解析器,JVM和.net平台上面。

引用
One of the big differences between JRuby and Jython is around the libraries. One of the tricky aspects of porting this kind of scripting language to the JVM is that these languages are usually closely intertwined with libraries implemented in C. Porting these libraries to Java involves rewriting the libraries in Java. Jython didn't do much of this, as a result many Python apps can't run in Jython. However the JRuby implementers decided from early on that their goal was to run Rails apps, as a result many libraries including all the Ruby standard libraries needed to be ported.

The fact that JRuby is a Ruby platform on the JVM means that in JRuby you have two kinds of objects - JRuby objects and Java objects. Although there are ways for the two to talk to each other and to convert there is a difference. There are times when you need to know whether you're dealing with a Java string or a JRuby string. With Groovy you don't have that boundary, there are just Java objects.


Martin接着指出来JRuby最大的问题在于:当把ruby整个类库移植到JVM平台的时候,凡是那些依赖于底层操作系统C库的ruby类库全部都需要用Java重写一遍。并且对于JRuby来说,程序员面临着编程方面的复杂性,需要分别处理JRuby类型的对象和Java类型的对象,而Groovy程序员则没有这些烦恼。

Martin认为,目前断言Groovy还是JRuby才会更有前途的问题还为时过早,选择哪种语言,更多是个人实际的需要:

引用
It's too early, or rather too difficult, to say if one language will win out. Both are pretty young, only just finding their feet on the JVM. On a more personal level, your choice has a lot to do with what you expect to do with it. If you are only interested in running on the JVM, then Groovy could well be the easier choice. You are working directly with Java's library and object model, and the syntax requires less getting used to. A strong reason to prefer Ruby is the fact that it lives in multiple implementations. Ruby is a tool you can use in a lot of other places. As a long time Rubyist, there's not much incentive for me personally to get heavily into Groovy, even though I actually like the language a lot from what I've seen of it.

Rails is an important factor. The Java world is hardly lacking in web frameworks, but Rails is widely liked by those who've used it. I've not got many reports yet about Grails (the Groovy knock-off) so can't give a firm opinion on that. But I can imagine that the ability to deploy web apps with Rails could be a major factor in making JRuby popular. Something else to look at is the growth of RSpec as a new spin on testing environments.


如果你仅仅关注Java语言和类库层面,那么Groovy是比较好的选择。而如果你本人就是一个ruby爱好者,并且在其他各种场合也在使用ruby,那么你基本上不会对Groovy产生什么兴趣,肯定会对JRuby感兴趣。

例外,Rails框架也是一个非常重要的决定因素,Java世界在web框架方面严重缺失,而基于Groovy的Grails框架并没有被广泛使用。因此对于把Rails项目部署到JVM平台来说,JRuby显然是一个很好的选择。此外还有人因为RSpec的吸引使用JRuby的。

引用
With any platform it's as important to consider the people involved in the community as much as any technical factors. Good people can overcome technical weaknesses quickly and a vibrant community is a potent source for big innovations. RubyPeople have formed a particularly strong community, which has already spawned things like Rails, Rake, and Rspec.


最后Martin补充,开发者社区其实也是一个决定性的因素,好的开发群体能够克服技术上的弱势,而社区的发展也是巨大创新的潜在来源。目前Ruby社区是一个非常强大的社区,并且已经衍生出来了Rails,Rake和RSpec这样的项目。

引用
There are plenty of people who dislike the hype around Rails and Ruby. But even if you dislike Ruby, the hype has led to a resurgence of interest in new languages. I doubt if the interest in Groovy would be anywhere near as great as it is if it wasn't for this hype, nor would Jython be awaking from its slumbers. The ruby/rails hype has also generated interest in other exotic JVM languages. The really nice thing here is that the JRuby people have been encouraging their dynamic rivals - recognizing that the point here is to encourage multi-lingual inter-operability and innovation.


最后Martin谈到,即使非常多的人因为围绕在Ruby和Rails周围的鼓吹而非常厌恶它们,但是这种社区的鼓吹也吸引了更多人的关注,从而引发了对新语言的兴趣。Martin不认为Groovy语言能够制造出来这样大的影响力。而Ruby/Rails的鼓吹事实上已经引起了JRuby这种JVM平台变异语言的诞生和更多的关注。并且一个非常好的现象就是,JRuby社区实际上也在鞭策它们的竞争对手-重新认识到多语言互操作性和创新性的的价值。

评论 共 12 条 发表评论

zhenjw 2008-06-20 13:14
一心一意的好,我看好Groovy
fangzhouxing 2007-12-12 16:39
准备学习和使用Groovy,实际感受一下。
xilaile 2007-12-11 03:05
赞同lordhong的观点!

>>>>>>>>>>>> 他们最大区别在于平台策略
完全同意!
Sam1860 2007-12-10 18:18
@shiren1118
>>Jruby同时具有2大强类,会走火入魔的

赞成这个。
我看好Groovy多一点,虽然2个我都不用:p
jjx 2007-12-10 12:06
就看jruby 每天都有更新这点,我看好jruby
agile_boy 2007-12-10 11:09
定位不同,社区不同,其发展自然也不同,我相信groovy+grails会逐渐被市场接受的。
而且比较赞成lordhong的观点
shiren1118 2007-12-10 08:31
Martin接着指出来JRuby最大的问题在于:当把ruby整个类库移植到JVM平台的时候,凡是那些依赖于底层操作系统C库的ruby类库全部都需要用Java重写一遍。并且对于JRuby来说,程序员面临着编程方面的复杂性,需要分别处理JRuby类型的对象和Java类型的对象,而 Groovy程序员则没有这些烦恼。


其实东西都是简单才强大,才容易接受,这大概是java超c++的一个原因吧
我们需要的是比java更强大的语言还是更优化呢?
Jruby同时具有2大强类,会走火入魔的

换因之,ruby社区越强大,未尝不是对groovy的促进!尤其现在各个大巨头比如oracle等的支持,以jjava的家底来看,瘦死的骆驼比马大
cddcdd 2007-12-10 08:26
对这个不是很感兴趣
但是不得不佩服日本人的效率,这么快就翻译成日文了
中文的马汀主页很久没有更新了。
Allen 2007-12-10 02:18
没有JRuby的话,RoR 2.0估计会等到明年第二季度才会出来……只要竞争不要发展成恶性肿瘤,那肯定是多多益善的咯。
lordhong 2007-12-09 22:12
martin选择JRuby是因为Ruby有更广泛的资讯潜力(consulting potential),groovy基于java,基于java的资讯早就做烂了。。。我是基于市场分析,和技术无关,哈哈!
coolnight 2007-12-09 21:51
引用
Java世界在web框架方面严重缺失,


唉唉唉...
dnwq 2007-12-09 19:36
好像很有道理

发表评论

您还没有登录,请登录后发表评论