简体   繁体   English

Ruby是否与Java一样跨平台?

[英]Is Ruby as cross-platform as Java?

You can compile a Java application and run it in any machine where the Java virtual machine is located, independently of the underlying hardware. 您可以编译Java应用程序并在Java虚拟机所在的任何计算机上运行它,而与底层硬件无关。

Since Ruby on Rails was built upon Ruby, I'm concerned if building software in Ruby in any environment is the same or not. 由于Ruby on Rails是基于Ruby构建的,我担心在任何环境中使用Ruby构建软件是否相同。 There exists versions of Ruby for Windows, Linux and Mac at least. 至少存在适用于Windows,Linux和Mac的Ruby版本。

So, could you do the same with a Ruby application and with a Java application? 那么,你可以用Ruby应用程序和Java应用程序做同样的事情吗? In other words, how cross-platform is Ruby? 换句话说,跨平台如何是Ruby?

EDIT: I mean Ruby by itself, not Ruby running in another virtual machine like in jRuby . 编辑:我的意思是Ruby本身,而不是像jRuby一样在另一个虚拟机中运行Ruby。 Should I expect more cross-platform gotchas development in Ruby than in Java or are both almost the same? 我是否期望在Ruby中开发比Java更多的跨平台陷阱或两者几乎相同?

Ruby is a scripting language and it is interpreted at the run time by the Ruby interpreter , The Ruby code is interpreted and converted to machine level language ie Assembly code . Ruby是一种脚本语言,它在运行时由Ruby解释器解释,Ruby代码被解释并转换为机器级语言,即汇编代码。 Talking about the platform Independence you can run ruby code in any of the the platform like Linux ,Windows or Mac if you have platform dependent Ruby Interpreter installed. 谈论独立平台,如果您安装了平台相关的Ruby解释器,您可以在任何平台(如Linux,Windows或Mac)中运行ruby代码。

Where as in Java , it is Compiled and converted to an intermediate byte class and this byte class is interpreted by platform dependent JVM (Java Virtual Machine ) . 在Java中,它被编译并转换为中间字节类,并且此字节类由平台相关的JVM(Java虚拟机)解释。

In that way you can think you Ruby source file as byte class which can be run on any platform ,with one difference byte class is already compiled but ruby source file will be compiled at the Run time . 通过这种方式,您可以将Ruby源文件视为可以在任何平台上运行的字节类,只有一个差异字节类已经编译,但ruby源文件将在运行时编译。

Ruby binds fairly closely to the underlying platform. Ruby与底层平台的关系非常紧密。 This is especially the case when it comes to process/threading mechanisms, and various forms of IPC. 当涉及到处理/线程机制和各种形式的IPC时尤其如此。 These are more significant challenges to overcome, compared to "trivial" ones as directory seperator, and so forth. 与作为目录分隔符的“普通”挑战相比,这些是要克服的更重要的挑战,等等。 I'm pretty sure that there isn't parity between, say, the Windows Ruby runtime and the Linux Ruby runtime. 我很确定Windows Ruby运行时和Linux Ruby运行时之间没有奇偶性。

With Java, the IPC/process/thread model is the same on all platforms that runs the JVM. 使用Java,IPC /进程/线程模型在运行JVM的所有平台上都是相同的。

As long as you don't touch hardware or threading, Ruby should work on the three major operating systems. 只要您不接触硬件或线程,Ruby就应该在三个主要操作系统上工作。 For web development, Ruby will mostly work the same everywhere. 对于Web开发,Ruby在大多数地方都会一样。 For more advanced applications, no, because it does not offer the abstractions of the JVM (that you probably have in mind). 对于更高级的应用程序,不,因为它不提供JVM的抽象(您可能已经考虑过)。

Java is cross platform. Java是跨平台的。 Ruby is not. Ruby不是。 It very much feels like an afterthought of, "oh we have windows users, let's try and get it working". 这听起来像是一个事后的想法,“哦,我们有Windows用户,让​​我们试着让它工作”。

In Java I have experienced less than 10 cross platform issues in years of heavy use. 在Java中,我在多年的大量使用中经历了不到10个跨平台问题。 The areas that this was in, were obviously areas that would be tricky. 这个领域显然是一些棘手的领域。 System/File system specifics. 系统/文件系统细节。

In ruby, I've experienced problems even when doing the first rails tutorial as have others ( https://github.com/twbs/bootstrap-sass/issues/696 ) . 在ruby中,即使在执行第一个rails教程时我也遇到过问题( https://github.com/twbs/bootstrap-sass/issues/696 )。 I wouldn't consider ruby cross platform. 我不会考虑ruby跨平台。 The platform relies on a whole host of dependencies, which anytime one of them uses anything platform specific the whole thing breaks. 该平台依赖于大量的依赖关系,这些依赖关系中的任何一个都会使用任何特定于平台的东西。 ie see this error: ExecJS::RuntimeError on Windows trying to follow rubytutorial 即看到此错误: Windows上的ExecJS :: RuntimeError试图遵循rubytutorial

I also inherited a largish ruby project and it relied on capistrano, webkit, bcrypt and these needed a dev build kit and native builds. 我还继承了一个大的ruby项目,它依赖于capistrano,webkit,bcrypt,这些需要一个开发构建工具包和本机构建。 It did not just work. 它不仅起作用。 See the people having trouble here: https://github.com/codahale/bcrypt-ruby/issues/116 It's funny, at one point they suggest someone follows a japanese post :) 看到有麻烦的人在这里: https//github.com/codahale/bcrypt-ruby/issues/116这很有趣,有一点他们建议有人关注日语帖子:)

如果没有别的,你可以运行JRuby,一个用Java编写的Ruby解释器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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