Ruby vs. Java Myth #5: It's a zero-sum game

  • Posted By Stuart Halloway on June 06, 2007

Previous Myths:

  1. Project Size
  2. Ruby feature X makes code unmaintainable
  3. Ruby is too hard
  4. It is easy to copy Rails' good ideas

Ruby is a great language, Java is a great platform. With Ruby running on a Java Virtual Machine, you get the best of both worlds.

As a language, Ruby is superior to Java for most general purpose programming tasks, as implied here, here, and here. (Some people disagree, mostly for reasons I have already covered under myths one, two, and three.)

As a platform, Java wins hands down. Until recently, Ruby's platform was simply the interpreter (MRI). Want to know how it works? Read the source code. Java provides a much better platform, including

  • a byte code instruction set
  • a portable class file format
  • powerful threading support
  • a thorough security model
  • lots of proven deployment options

Plus Java has more implementations than you can shake a stick at, running everywhere you want to be.

So can't we all just get along? I want to live in a world where language preference does not define a programmer. We'll write code in Ruby, or Scheme, or Scala, or Erlang. And we can all live in harmony on a JVM anywhere.

Want to help create this world? Here are some steps you can take:

  • Contribute to the JRuby project.
  • Write some parts of your next Java application in JRuby. Your dependency injection framework should make this trivial to integrate. If it doesn't, get a new one. You can even get a static typing methadone shot by making your JRuby code conform to a Java interface.
  • Manage your Java application with rake instead of ant (and contribute some code to help others do the same). I have yet to meet a single developer who prefers ant to rake. As I often say, WWJDDD?
  • Unit test some Java code in JRuby Test::Unit.

Happy coding!

Comments
  1. afsinaJune 06, 2007 @ 01:38 PM

    This Ruby-Java myth series was really itself a complete myth. You deliberately dodged the most obvious shortcomings of Ruby successfully (JRuby or not). But, for you to know that many people disagree, i will count them again. - Ruby is SLOW. it is possibly the slowest of popular scripting languages. - With Ruby you can do some things, but it is easy to stuck when you need something low level, immediately you will find yourself in a mixed code project, or C hell. - Ally Ruby IDE’s SUCK. refactoring in dynamic languages, especially in ruby is very hard. The huge amount of Java IDE’s with excellent refactoring-editor support i can write code faster then Ruby for God’s sake. - Ruby syntax is hard to read (and it is ugly IMO). Especially if it is written by a show off, you have no chance. it is not safe enough comparing with java. A ruby team member told once, if your team is not consist of Ninjas, don’t code non trivial projects in ruby. Give me a Java code written by a moderate developer any day. Java makes you think modular. - RoR is not sclalable enough. even a useless and rather simple application like twitter cannot handle the load. Tomcat can eat those application as breakfast. - Ruby Threading is a joke. - there is no Ruby resources, you will need to handpick ninjas like you, which is not easy.

    So please, stop FUD and show us the code.

  2. Anthony ChavesJune 06, 2007 @ 03:15 PM

    You said “As a platform, Java wins hands down.” and you’re 100% correct. The powerful features of the Java platform are the reason the Java language is so widespread. People are not language bigots so much as they need the platform. Given an option most people will take something that is easy to use over something that is hard to use. Ruby has a lot going for it in that aspect. Unfortunately the Ruby platform doesn’t supply all the features required by people that rely on the Java platform. Until recently it was difficult to use the Java platform without using the Java language.

    Your ideal world of everyone getting along in one big happy JVM is an ideal world for a lot of us. Ruby, Groovy, Erlang, etc. have a lot to take advantage of and a common platform goes a long way in promoting the power of these languages. Hopefully people, including myself, act on at least one of your suggestions for creating this world.

    It’s interesting too, that we are exploring the idea of running multiple languages on a common platform. It’s almost starting to sound like .NET… :-)

  3. anonymousJune 06, 2007 @ 03:20 PM
    Want to help create this world? Here are some steps you can take:

    I want to create a world where ruby zealots get a life.

    Happy coding!

  4. anonymousJune 06, 2007 @ 06:04 PM

    Those who say they can do it faster in Java with an IDE should sit down for a couple of days and really learn Ruby as a language (not just the Rails framework). Having things in the language like mixins (modules), dynamically extensible classes, classes as true objects, and especially closures just make writing elegant code a dream.

    I’ve been writing Java code going on 10 years now, and I think I’m pretty decent at it. I’ve been doing Ruby for just under the last two, and recently had to go back to doing some Java coding. The pain of having to adjust my thinking back to Java’s limited syntax was just painful. For example, in Ruby I have a set of methods that handle tags on a database model, and I just mix it into each of my model classes with a single line. In Java you have to either serious overload the inheritance structure (add tons of random method to a base class or try to create tricky inheritance chains), cut-and-paste gobs of similar code between classes and use interfaces (so much for DRY), or use something like aspects (so much for KISS).

    Why do it in Java? Java definitely much faster than Ruby. But for something like a web app, your performance probably isn’t going to hinge on the speed of your language. Most well-designed Rails apps I’ve used fare better than most Java web apps out there, just ‘cause the overhead of J2EE is such a bear.

  5. JasonJune 06, 2007 @ 09:53 PM

    “I want to live in a world where language preference does not define a programmer. We’ll write code in Ruby, or Scheme, or Scala, or Erlang.”

    Is it just me, or does the idea of maintaining non-trivial apps in whatever-language-the-developer-of-felt-like-using-that-day sound more like Hell than paradise? (Assuming that over time almost every language will be used on ONE project, if it lives long enough…)

  6. JoeJune 10, 2007 @ 06:08 AM

    afsina – “stop FUD and show us the code”... have you tried picking up their most recent book – R4JD – http://www.pragmaticprogrammer.com/titles/fr_rails4java/

    no fud, just the facts.

    It’s amazing to see the amount of backlash that is received from what I consider to be some pretty even handed comparisons of two languages.

  7. afsinaJune 10, 2007 @ 09:40 PM

    as long as ruby is 50-100 times slower in many operations, which is only one of the things i challange, i do not want to use it for my main development because sooner or later i will stump into a performance issue. you guys are thinking developement world is database driven simple web applications.

  8. Angus McDonaldJune 11, 2007 @ 12:09 AM

    Stu,

    Great set of posts, I think you’ve taken a pretty even-handed approach. Having worked with Java and .NET and played with Rails it is very interesting seeing Rails quickly catch up with those other platforms in terms of IDEs and other solutions. Perhaps it’s just because I’m an old fart, but I remember Java being the latest and greatest ‘idea’ and not having the enormous enterprise support it does now.

    afsina: “A ruby team member told once, if your team is not consist of Ninjas, don’t code non trivial projects in ruby.” Huh. If you are coding non-trivial projects then you better be hiring code-ninjas or you’re toast anyway. Coding with a ‘moderate developer’ in any language is only going to get you into problems anyway – read Software Craftsmanship by Peter McBreen for an in-depth analysis of the problems that the software engineering (i.e. plug any warm body into the programmer slot) can get you into.

    “RoR is not sclalable enough. even a useless and rather simple application like twitter cannot handle the load.” My reading of Twitter’s issues is that they would have run into difficulties at some stage no matter what platform they went for – Rails allowed them to get up and running for a lower outlay and arguably much faster than Java. The fact that it was an open-source solution and thus could be fixed by them was a plus – being landed with a proprietary framework or language that cannot be fixed by the team sucks – and I speak from experience.

  9. Brian PontarelliJune 11, 2007 @ 08:23 PM

    Best tool for the job right? Pragmatism is definitely something you seem to be driving towards. I think your points are good, but the presentation somewhat confusing and without a 360-degree perspective at times.

  10. JeffJuly 06, 2007 @ 04:07 PM

    refactoring in dynamic languages, especially in ruby is very hard

    Since Smalltalk is where automated refactoring tools originated, why does this myth persist?

  11. anonJanuary 08, 2008 @ 04:29 PM

    Well after having gone Rails, then gone off Rails (due to issues well articulated above), I have returned to Rails again in 2008. Why? There is an assumption made above that in the world of applications, the situation is not hopeless. Therefore we can use something simple enough like PHP and have a team etc. Let me tell you that this is not the case. The situation is hopeless. Development == pain+frustration / tolerance+determination. What makes development impossible is a lack of the denominators.

  12. Jonathan PletzkeJanuary 25, 2008 @ 06:22 PM

    Funny how the negative comments sound a lot like the negative comments of the past when Smalltalk and Java were exciting, and folks developing in C++ and C thought it would never catch on. Though many Smalltalk apps were converted to Java, a number live on.

    Come to think of it, the bashing also happened prior to the JVM issue, with the “overhead” of having C+, especially as the pre-compiler turned it into C before anyone came up with a C+ direct compiler. Same for Lisp. People thought C was new and risky, as opposed to safe and good COBOL.

    Choosing the right tools for the right problem is a predictor of success. Writing device drivers in: Ruby? No. Java? No. C++? OK. C? Yes. Writing a high level, quick to deploy application in: Ruby? Yes. Java? OK. C++? Maybe. C? No.