简体   繁体   English

Java优于Ruby / JRuby的优点

[英]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 more developers experienced with Java than with Ruby. 许多开发人员使用Java而不是使用Ruby。
  • Many existing libraries in Java (That helps JRuby too). Java中的许多现有库(这也有助于JRuby)。
  • Static typechecking (can be seen as advantage and as disadvantage). 静态类型检查(可以看作是优势和劣势)。
  • Existing codebase that has to be maintained. 必须维护的现有代码库。
  • Good tool-support. 良好的工具支持。
  • More and deeper documentations and tutorials. 更多更深入的文档和教程。
  • More experiences with good practices and pitfalls. 有关良好实践和陷阱的更多经验。
  • More commercial support. 更多的商业支持。 That's interesting for companies. 这对公司来说很有意思。

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,但我可以猜到以下几点:

  • Java has more documentation (books, blogs, tutorial, etc.); Java有更多文档 (书籍,博客,教程等); overall documentation quality is very good 整体文档质量非常好
  • Java has more tools (IDEs, build tools, compilers, etc.) Java有更多的工具 (IDE,构建工具,编译器等)
  • Java has better refactoring capabilities (due to the static type system, I guess) Java具有更好的重构功能 (由于静态类型系统,我猜)
  • Java has more widespread adoption than Ruby Java比Ruby更广泛采用
  • Java has a well-specified memory model Java有一个明确指定的内存模型
  • As far as I know, Java has better support for threading and unicode (JRuby may help here) 据我所知,Java对线程和unicode有更好的支持(JRuby可能会在这里提供帮助)
  • Java's overall performance is quite good as of late (due to hotspot, G1 new garbage collector, etc.) Java的整体性能最近很好(由于热点,G1新的垃圾收集器等)
  • Nowadays, Java has very attractive and cheap server hosting: appengine 如今,Java拥有非常有吸引力和廉价的服务器托管: appengine

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虚拟机 ,经过十多年的改进,包括:

  • just in time compilation in the HotSpot compiler (JIT - compiling byte code to native code) 及时编译HotSpot编译器(JIT - 将字节代码编译为本机代码)
  • a plethora of garbage collection algorithms and tuning parameters 过多的垃圾收集算法和调整参数
  • runtime console support for profiling, management etc. of your application ( JConsole , JVisualVM etc) 运行时控制台支持应用程序的分析,管理等( JConsoleJVisualVM等)

I like this Comparison(Found on link Given by Markus!Thanks!)... Thanks to all... i am also expecting some more discrete advantages 我喜欢这个比较(在Markus给出的链接上发现!谢谢!)...感谢所有...我也期待一些更独立的优势

Java-Ruby比较


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: 如果我尝试枚举这些属性,它将是:

  • of course strong static typing 当然强大的静态打字
  • the grammar of language is a LALR(1) grammar - so it is easy to build a parser 语言的语法是LALR(1)语法 - 所以很容易构建一个解析器
  • fully qualified names (packages) 完全限定名称(包)

What we've got in the IDE so far, for example Eclipse: 到目前为止我们在IDE中得到了什么,例如Eclipse:

  • great capabilities of exploring very large code bases. 探索非常大的代码库的强大功能。 You can unambiguously find all references, call hierarhy, usages of classes or public and protected members - it is very valuable when you studying the code of the project or going to change something. 您可以毫不含糊地找到所有引用,调用hierarhy,类的用法或公共和受保护的成员 - 当您研究项目代码或要更改某些内容时,它非常有价值。
  • very helpful code editor. 非常有用的代码编辑器 I noticed that when I writing code in the Eclipse's java editor I'm actually typing by hand only names of calsses or methods and then I press Ctrl+1 and editor generates a lot of things for me. 我注意到当我在Eclipse的java编辑器中编写代码时,我实际上只是手工输入calsses或方法的名称,然后我按下Ctrl + 1并且编辑器为我生成了很多东西。 And especially good that eclipse encourage you to write the usage of piece of code first and even before the code is aclually writen. 特别好的是,eclipse鼓励你首先编写代码片段的用法,甚至在代码被写入之前。 So you do the method call before you create the method and then editor generates the method stub for you. 因此,在创建方法之前执行方法调用,然后编辑器为您生成方法存根。 Or you add extra arguments to the method or constructor in the place when you're invoking it - and editor change the signature for you. 或者,当您调用它时,在该位置为方法或构造函数添加额外的参数 - 编辑器会为您更改签名。 And enev more complicated things - you pass some object to the method that accept some interface - and if the object's class do not implement this interface - editor can do it for you... and so on. 而且更复杂的东西 - 你将一些对象传递给接受某个接口的方法 - 如果对象的类没有实现这个接口 - 编辑器可以为你做...等等。 There's a lot of intresting things. 有很多令人感兴趣的东西。

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的否定:

  • There is a lot of duplication in libraries and frameworks available for Java. Java中可用的库和框架有很多重复。
  • Java developers/communities tend to create over complicated solutions to simple problems. Java开发人员/社区倾向于为简单问题创建复杂的解决方案。
  • There is a lot more legacy in Java to maintain. Java中有更多的遗产需要维护。
  • Too much pandering to business users has introduced cruft that makes middle managers feel better. 对业务用户的过度追求引发了一些让中层管理人员感觉更好的事情。 In other words, some philosophies in Java are more concerned with BS instead of getting the job done. 换句话说,Java中的一些哲学更关注BS而不是完成工作。 This is why companies like to use Java. 这就是公司喜欢使用Java的原因。
  • You'll generally need to write more code in Java than Ruby. 您通常需要在Java中编写比Ruby更多的代码。
  • It takes a lot more configuring/installing/setup to get a fully working Java development environment over Ruby. 需要更多的配置/安装/设置才能通过Ruby获得完全可用的Java开发环境。

Positives for Java: Java的积极因素:

  • Speed. 速度。
  • Documentation. 文档。
  • Lower level language than Ruby, which could be a good thing or a bad thing, depending on your needs. 低级语言比Ruby,这可能是一件好事或坏事,取决于您的需求。

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: 还有更多选择:

  • Developers - lots to hire 开发人员 - 招聘人员
  • Libraries - lots of wheels already invented. 图书馆 - 已经发明了许多轮子。
  • IDE's - lots of development environments to choose from. IDE - 许多开发环境可供选择。 Not only just vi/emacs + a shell. 不仅仅是vi / emacs +一个shell。
  • Runtimes - if you for some reason do not like the JVM you use on the system, you can either download or buy another implementation and it will most likely Just Work. 运行时 - 如果由于某种原因你不喜欢你在系统上使用的JVM,你可以下载或购买另一个实现,它很可能就是Just Work。 How many Ruby implementations are there? 有多少Ruby实现?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM