[英]Advantages of Java over Ruby/JRuby
I am learning Java. 我正在学习Java。 I have learned and used Ruby.
我学习并使用过Ruby。 The Ruby books always tell the advantages of Ruby over Java.
Ruby书籍总是讲述Ruby优于Java的优势。 But there must be some advantages, that's why lots of people (especially companies) use Java and not Ruby.
但必须有一些优势,这就是为什么很多人(特别是公司)使用Java而不是Ruby。 Please tell the absolute(not philosophical!) advantages of Java over Ruby.
请告诉Java相对于Ruby的绝对(不是哲学!)优势。
Many of these advantages are the result, that the Java-ecosystem is more matured, than that around Ruby. 其中许多优点都是Java生态系统比Ruby更加成熟的结果。 Many of these points are subjective, like static vs. dynamic typing.
其中许多点都是主观的,如静态与动态类型。
I don't know Ruby very well, but I can guess the following points: 我不太了解Ruby,但我可以猜到以下几点:
Please tell the absolute … advantages of Java over Ruby
请告诉我Java的绝对优势......
Programmers should rarely deal in absolutes. 程序员应该很少处理绝对值。
I'll dare it, and say that as a rule , static typing (Java) is an advantage over dynamic typing (Ruby) because it helps recognize errors much quicker, and without the need to potentially difficult unit tests 1) . 我敢说,并且说通常 ,静态类型(Java)比动态类型(Ruby)更有优势,因为它有助于更快地识别错误,并且无需潜在的困难单元测试1) 。
Harnessed intelligently, a strong type system with static type checking can be a real time-saver. 智能地利用,具有静态类型检查的强类型系统可以节省时间。
1) I do not oppose unit testing! 1)我不反对单元测试! But good unit testing is hard and the compiler can be a great help at reducing the sheer number of necessary test cases.
但良好的单元测试很难,编译器可以帮助减少必要测试用例的数量。
Reason #1. 原因#1。 There's a lot of legacy Java code out there.
那里有很多遗留的Java代码。 Ruby is new, there's not so many programmers who know it and even fewer who are good at it.
Ruby是新的,没有那么多的程序员知道它,甚至更少的人擅长它。 Similarly, there is a lot more library code available for Java than Ruby.
同样,Java可用的库代码比Ruby多得多。
So there may be Technical reasons Ruby is better than Java, but if you're asking for Business reasons, Java still beats it. 所以可能有技术原因Ruby比Java好,但如果你要求商业原因,Java仍然胜过它。
The Java Virtual Machine , which has had over a decade of improvements including: Java虚拟机 ,经过十多年的改进,包括:
I like this Comparison(Found on link Given by Markus!Thanks!)... Thanks to all... i am also expecting some more discrete advantages 我喜欢这个比较(在Markus给出的链接上发现!谢谢!)...感谢所有...我也期待一些更独立的优势
And its Great!! 它的伟大!!
The language. 语言。
My opinion is that the particular properties of the Java language itself lead us to the powerful capabilities of the IDEs and tools. 我的观点是Java语言本身的特定属性使我们获得了IDE和工具的强大功能。 These capabilities are especially valuable when you have to deal with very large code-base.
当您必须处理非常大的代码库时,这些功能特别有用。
If I try to enumerate these properties it would be: 如果我尝试枚举这些属性,它将是:
What we've got in the IDE so far, for example Eclipse: 到目前为止我们在IDE中得到了什么,例如Eclipse:
There is a LOT of tools for Java. Java有很多工具。 As an example of a one great tool I want to mention Maven.
作为一个伟大的工具的例子,我想提到Maven。 Actually, my opinion is that the code reuse is really possible only when we have such a tool like Maven.
实际上,我认为只有当我们拥有像Maven这样的工具时才能实现代码重用。 The infrastructure built around it and integration with IDE make feasible very intresting thinsg.
围绕它构建的基础架构以及与IDE的集成使得非常有趣的thinsg成为可能。 Example: I have m2eclipse plugin installed.
示例:我安装了m2eclipse插件。 I have new empty project in the Eclipse.
我在Eclipse中有一个新的空项目。 I know that there is a class that I need to use (reuse actually) somewhere in the repositories, let say StringUtils for example.
我知道我需要在存储库中的某个地方使用一个类(实际重用),比如说StringUtils。 I write in my code 'StringUtils', Eclipse's editor tell me that there is no such class in the project and underlines it with red.
我在代码'StringUtils'中编写,Eclipse的编辑告诉我项目中没有这样的类,并用红色强调它。 I press Ctrl+1 and see that there is an ability to search this class in the public repository (actually in the index, not the repository itself).
我按Ctrl + 1,看到有能力在公共存储库中搜索此类(实际上在索引中,而不是存储库本身)。 Some libs were found, I choose one of them at particular version and the tool downloads the jar, configures my project's calsspath and I alredy got all that I need.
找到了一些库,我在特定版本中选择了其中一个,并且该工具下载了jar,配置了我项目的calsspath,我已经得到了我需要的所有内容。
So it's all about programmer's productivity. 这就是程序员的工作效率。
The JVM. JVM。
My opinion is that the JVM (Sun's HotSpot particularly) is a one of the most intresting pieces of software nowadays. 我的观点是,JVM(特别是Sun的HotSpot)是当今最引人注目的软件之一。 Of course the key point here is a performance.
当然,这里的关键点是表演。 But current implementation of HotSpot JVM explores very cutting edge ways to achieve such really great performance.
但是,HotSpot JVM的当前实现探索了实现如此卓越性能的非常前沿的方法。 It explores all possible advantages of just-in-time compiling over static, collects statistics of the usage of code before JIT-compile it, optimise when it possible virtual calls, can inline a lot more things that static compiler can, and so on.
它探讨了即时编译静态的所有可能优势,在JIT编译之前收集代码使用情况的统计信息,优化虚拟调用的可能性,可以内联更多静态编译器可以使用的东西,等等。 And the great thing here that all this stuff is in the JVM, but not in the language itself (as contrary with C# as example).
在这里,所有这些东西都在JVM中,而不是语言本身(与C#相反)。 Actually, if you're just learning the Java language, I strongly encourage you to learn the details of modern implementations of JVM, so you know what is really hurt performance and what isn't, and do not put unnecessary optimizations in the Java code, and do not afraid to use all possibilities of the language.
实际上,如果你只是学习Java语言,我强烈建议你学习JVM现代实现的细节,这样你就知道什么是真正的性能损害,什么不是,并且不要在Java代码中加入不必要的优化,并且不要害怕使用该语言的所有可能性。
So... it's all about IDEs and tools actually, but by some reason we have them for Java not for any other language or platform (.NET of course is a great competitor in the Windows world). 所以...它实际上是关于IDE和工具的,但由于某种原因,我们将它们用于Java而不是任何其他语言或平台(.NET当然是Windows世界中的一个很好的竞争对手)。
Network effect . 网络效应 。 Java has the advantage of more people using Java.
Java具有更多人使用Java的优势。 Who themselves use Java because more people use Java.
谁自己使用Java,因为更多的人使用Java。
If you have to build a big software, you'll need to collaborate. 如果您必须构建一个大型软件,则需要进行协作。 By having a lot of programmers out there, you are sure that there will be someone that can be asked to maintain your software even if the original developers have left the company.
通过让很多程序员在那里,您确信即使最初的开发人员离开公司,也会有人被要求维护您的软件。
Static type checking and good Java IDE offer no magic and this is good for a lot of maintainer instead of Ruby. 静态类型检查和良好的Java IDE没有任何魔力,这对很多维护者而不是Ruby有好处。
It is not sufficient to indicate that java is statically typed and ruby is dynamically typed. 仅表示java是静态类型并且ruby是动态类型是不够的。
Correct me if I'm wrong, but does this cover the fact that in ruby you can add to and even change the program (class definitions, method definitions etc) at runtime? 如果我错了,请纠正我,但这是否涵盖了这样一个事实:在ruby中你可以在运行时添加甚至更改程序(类定义,方法定义等)? AFAIK you can have dynamically typed languages that are not "dynamic" (can be changed at runtime).
AFAIK您可以拥有非“动态”的动态类型语言(可以在运行时更改)。
Because in Ruby you can change the program at runtime you don't know until you've actually run the program how it is going to behave, and even then you don't know if it will behave the same next time because your code may have been changed by some other code that called the code you're writing and testing. 因为在Ruby中你可以在运行时更改你不知道的程序,直到你实际运行程序的行为方式为止,即使这样你也不知道下次它是否会表现相同,因为你的代码可能已经被一些其他代码更改,这些代码调用了您正在编写和测试的代码。
This predictability is, depending on the context, the advantage of Java - one of the contexts where this is an advantage is when you have a lot of developers of varying skill levels working on a fairly large enterprise application. 这种可预测性取决于上下文,Java的优势 - 这是一个优势的背景之一是当你有大量不同技能水平的开发人员在一个相当大的企业应用程序上工作时。
IMHO, what one person considers an advantage might be a disadvantage for someone else. 恕我直言,一个人认为有利的可能对别人不利。 Some people prefer static typing while others like dynamic.
有些人喜欢静态打字而有些人喜欢动态打字。 It is quite subjective and depends largely upon the job and the person doing it.
这是非常主观的,主要取决于工作和做这件事的人。
I would say just learn Java and decide for yourself what its strong points are. 我会说只是学习Java并自己决定它的优点是什么。 Knowing both languages yourself beats any comparisons/advice some other person can give.
了解这两种语言本身可以胜过其他人可以提供的任何比较/建议。 And its usually a good thing to know another language, so you're not wasting your time.
知道另一种语言通常是件好事,所以你不要浪费时间。
Negatives for Java: Java的否定:
Positives for Java: Java的积极因素:
None of my points are very scientific, but I think the differences in philosophy and personalities behind Java and Ruby is what makes them very different to each other. 我的观点都不是很科学,但我认为Java和Ruby背后的哲学和个性差异使他们彼此之间的差别很大。
This has probably been beaten to death, but my personal opinion is that Ruby excels at quickly created web apps (and frameworks) that are easy to learn, beautiful to read, and are more than fast enough for web apps. 这可能已经被打死了,但我个人的观点是,Ruby擅长快速创建的Web应用程序(和框架),这些应用程序易于学习,阅读美观,并且对于Web应用程序而言足够快 。
Where Java is better suited for raw muscle and speed. Java更适合原始肌肉和速度。
For example, I wrote a Ruby program to convert a 192 MB text file to a MongoDB collection. 例如,我编写了一个Ruby程序,将192 MB的文本文件转换为MongoDB集合。 Ruby took hours to run.
Ruby需要几个小时才能运行。 And the Ruby code was as simple/optimized as you could get (1.9.2).
Ruby代码就像你可以得到的那样简单/优化(1.9.2)。
I re-wrote it in Java and it runs in 4 minutes. 我用Java重新编写它,它在4分钟内运行。 Yes.
是。 Hours to 4 minutes.
小时到4分钟。 So take that for what it's worth.
因此,请考虑它的价值。
更好的表现
There are more choices: 还有更多选择:
Please note that this has nothing to do with the LANGUAGES as such :) 请注意,这与LANGUAGES无关:)
Reading up on this : Is Ruby as cross-platform as Java? 阅读本文: Ruby是否与Java一样跨平台? made me realize at least one factual advantage of java over ruby:
让我意识到java优于ruby的至少一个事实优势:
The J2ME-compatible subest of java is more portable than ruby J2ME兼容的java子程序比ruby更便携
as long as JRuby won't run on J2ME which may be forever 只要JRuby不能在J2ME上运行,这可能是永远的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.