Thursday, October 13, 2005

Why do Java programmers like Ruby?

As a (mostly ex-) Java programmer myself who prefers Python to Ruby, I'm puzzled by what seems like a rush of Java programmers to embrace Ruby as though it were the only dynamic language on the planet.

I understand that it's mostly because of the success of Rails, which definitely came at the right time with the right marketing. But Ruby really doesn't seem like a good philosophical match with Java to me.

Java, to a large degree, tried to be "C++ done right." That is, C++ without all the misfeatures that seemed good at the time but whose benefit turned out to not be worth the cost in complexity for developers. Java is a very orthogonally designed language; there is usually one obvious way to accomplish something. Python shares this. Ruby, OTOH, takes the C++ and Perl philosophy of "there's more than one way to do it," with predictible effects on maintainability. ("Perl," said a former co-worker to me yesterday, "is the drunken frat boy of languages.")

I could point at other areas where Python seemed like a better fit to me, like real threading support, etc., but the core issue seems to be: what is the language's philosophy? Is it trying to help my team write maintainable, readable code, or is it more interested in being "clever?"

Java and Python were designed for readability. C++ and Ruby were designed to be clever.

About the only thing Ruby has going for it, from this Java developer's perspective, is braces. Ahh, comforting braces. Are people that afraid of syntactical change?

I guess now I know how Lisp developers feel, a little.


Tom Copeland said...

Hi Jonathan!

I learned Ruby because it was being used on a big project that I was working on... and I've never had the need to learn Python. Perhaps if I had learned Python first I would have been more happy with it; don't know.

Anecodotally, whenever I try to make even the most minor change to Mailman, I end up screwing up the indentation somehow and getting a stacktrace. Argh.

Heh, I'm not sure that Ruby's philosophy is "we are clever" :-) I guess you'd have to ask Matz about that...

Matt said...

Your right, it does seem many Java programmers gravitate towards Ruby.

I disagree that Java shares the design philosophy of having only one obvious way to accomplish something. Maybe some of the basic concepts (everything is a class, wrap all exception throwing code blocks with try/catch) reflect it, but I have run into situations where there is no obvious "best way".

I remember once writing image drawing code and there were several built-in classes to choose from, some were subclasses of others, some could only be constructed from a particular source, it was a mess. Digging through forums would eventually reveal which of these classes was the most efficient, and so that's what I'd end up using. (Though this would occur, of course, after having written code using that appeared to be the obvious classes for the job based on the documentation)

Regardless, Java is missing a very important part of the Python design philosophy:

"Simple is better than complex.
Complex is better than complicated."

Ruby may be clever, but it also is less readable than Python. Maybe that makes the Java people feel at home. (I kid, I kid)

Matt said...

Make that "You're right...".

My apologies, shouldn't post past my bedtime.

Michael Sica said...

John, you hit the nail on the head.

"I understand that it's mostly because of the success of Rails, which definitely came at the right time with the right marketing."

Say no more...

Jonathan Ellis said...

Matt -- good point; when I'm saying "Java" and "Python" I mean Java-the-language and Python-the-language, not the libraries. Java's stdlib does lack orthogonality in places... but after 10+ years, it's hard to blame them. Python has learned some lessons in that time, too.

Frederick Ros said...

Hum ... I do not really agree ...

I tried to learn Python 2 times:
* the first tim eI disagree (like a lot of people) on the "space is important" behavior which remind me too much Fortran ... and I know the mess regarding tabs/space ...

* The second time, I choose to overcom ethi ssyntactic problem, but then I can't figure why I have to add self as 1st param of each method, and most important .. I do not want to be forced to do things in one way .. The "one way to do things" was not , really not for me ...

Then I encountered Ruby .. and things were *much* better ... more readable IMHO than Python, and cleaner.

So all in one I think it's a matter of taste ...

yozzeff said...

i first learned python some 7 years ago and for a very very long time it
was the only seriously contender for
anything done dynamic.
only last year i started to look for
something different. the reason being
that python seriously sucks when it
comes to doing DSLs that are to be used from the host language without use of a third party BNF library.
i have written a blog sometime ago
on choosing the right dynamic language for the JVM
i dont think that python is up to ruby when it comes to closures. the syntax is clear and precise - much clearer than anything python has to offer at the moment.
and the PEP 343 doesnt look that promising either.

Fred said...

What also might be a factor is that Ruby's object model is different.

In Ruby, there's a distinction between methods and attributes. You cannot access an objects's attributes directly. OK, this is not entirely true, but if an object foo has an attribute @bar then you cannot say foo.@bar or Rather, you have to use methods to access it. Getters and setters, just like in Java. Except that Ruby makes it super easy to create these.

In Python, on the other hand, you have access to an object's attributes by default. Of course, you can add getters and setters by playing with priorities or __setattr__... but it's more work than in Ruby, and feels less natural. (Compare code that tries to control attribute access to code that doesn't.)

People are often superficial. This thread brings out again that people give up on Python, or don't give it a real chance, because of whitespace and the "self" issue. It would not be unthinkable that (Java) programmers are uncomfortable by the way Python handles objects, and more comfortable by the way Ruby does it, because they can still do the things they are familiar with.

Jonathan Ellis said...

That's true; Python's object model is indeed different from the C++/Java/C# "mainstream." It's not "bolted on OO" as some people claim; it's just a different design. Good point.

Ian Bicking said...

Sometimes it's nice to do something completely different. Especially coming from the stifling world of Java, a little sloppiness and a bit of a punctuation explosion probably feels pretty fun and freeing. Python might too, but isn't quite as up-front with it. So anyway, I think the dissimilarities could actually work for Ruby, at least with respect to initial enthusiasm and general wonder.

Python Blog said...

I was recently trying to convert a Java developer to the joys of Python but he was having none of it. Insisting Ruby would be much easier to learn.

Its quite clear that Python would be a better transition although I have to admit I'm a big fan of both and I'm a former Java developer.

Kevin said...

I am a Java programmer for some years.

In August and September this year, I had some free time so I studied Python and Ruby casually. My experience is very limited.

Python, I don't why, doesn't give me an exciting feeling. I had those kind of feelings when first encountered Perl, or Java some years ago. That feeling could keep me up all night long. Python is beautiful, powerful and used by smart people(during that month I actively took part in discussions in a python mailing list so I know that firsthand). But still I never got a sense of addictiveness. It feels foreign to me. Maybe this is mainly because of the whitespace, the braces, the "self" things. It's possible that if I spent more time on it, my feeling could change. But at least to me, the whole "there is one obvious way to do thing" was slightly a turn off. A little too bland?

Ruby is a different story. It has lots of things fallen into places nicely right from the start. I feel very comfortable using it and am often amazed by its clever design. This cleverness is very appealing to average Joe Smith programmer (who is also experienced) like myself.

Sorry for the rambling. Just my own experience. Right now in my work are Java and PHP, and in spare time, i am reading Ruby books. Havn't tried ROR yet.

Anonymous said...

I'm a Java programmer curious in all the buzz about Ruby, and my two cents is that you may be right that the appeal is more about Rails, and to use Rails, you have to learn Ruby. But more specifically, a lot of Java programmers are building complex, multitier webapps, for which there is no orthogonal approach. Struts or Spring? JDBC, or Hibernate, or iBatis? Tapestry or JSF or Wicket? And those are only a few of the choices, plus then I have to learn Spring to tie it all together! Another factor is the trend towards "coding in XML" that's come up in the last couple years.

Rails appeals because there's so little choice about how to do something with it, IMO, and because it avoids the whole stack of frameworks you need to learn to be able to deliver a webapp, and you don't need a potpourri of XML files with different DTDs to do it.

Anonymous said...

Hi Jonathan,

Java programmers and others are switching to Ruby because they don't care about philosophy (clever or otherwise) --- they care about getting solutions to real problems built as quickly as possible. For example, while the Python community continues to squabble (Django! TurboGears! No, wait, I've created a new one!), there are now four books on Rails, and more in the works.

Greg (a confirmed Pythonista)

John Mudd said...

I've also met Java programmers that prefer Ruby over Python. The main reason was they don't like Python's whitespace versus Ruby's braces. I was really surprised until I met more people that say the same (illogical) thing.

I mentioned Jython. They counter by saying Ruby has something similar. Even though I'm not sure they're correct.

Pete McKinstry said...

I'm a java guy and I prefer Python. I agree with you that certain asepcts of Ruby are very perl-ish. I just wish python used something other than identation for block separation.

Paddy3118 said...


Shift your focus. Its not primarily the programmoing language. You are solving someones problem. Actually its yesterdays problem that you will solve tomorrow. You need a programming language that is not only good at solving the problem you have solved, but that can be easily modified to solve the evolved problem the customer has now.

Python has a much clearer focus on making programs that are easier to maintain.

Addressing those coders that preferred "more ways to do it": what happens when you have to read someone elses code that has chosen a different way to express something than your pet way?
The flip side of there being more than one obvious way to do something is that there are other less obvious ways (to you), that you can bet someone else would use. The resultant code is therefore less readable.

On the other hand, If you are after a web framework to deliver some solution and Rails is a better fit than everything else you have tried then go for it.

If you are after a programming language then you should try Python. Don't let the significant white-space throw you. It is a part of the learning curve but so long as you stick to not mixing spaces and tabs, and indent consistently, then you won't go wrong.
Another of Pythons strengths is that it isn't just an object oriented language. Everything is an object, objects arn't bolted on, but you don't have to write in an OO style.

Anonymous said...

I'm coming to Ruby from Python. There are some things I really like about Python, but the whitespace delimiters always seems to cause hassles when working with other coders - I always use the same settings, but when you try to use someone else's code, it's a pain in the butt.

Cliff said...

I'm wondering the same thing. Why do so many Java developers only see Ruby? There's the Groovy language ( which appears just as powerful. Hell Groovy even has Grails. I've not written or read too much Python code except for a few Amarok scripts and other nick knacks floating around my Linux distro. On the other hand I've always wanted to try the language. I particularly don't like Ruby too much, mostly because I find it's syntax to be too "clever". Overall I don't argue that it is a strong language it's just not my taste. Also there's the learning curve that comes with it. That said, I've tried Ruby before (unsuccesfully tried to get Gem to work through our http proxy) and will try it again in the future. While I think it does boild down to a matter of taste, it puzzles me that many Java developers don't see the potential in the Java platform. I've babbled long enough, time to get some work done.

Anonymous said...

Could it be that the main reason Java programmers flock to Ruby is really something as mundane as the fact that Ruby was extensively hyped to Java programmers whereas Python wasn't?

pikemon said...

I got into python around year 2000 and got really excited about it. Unfortunately, I was working at a M$ firm and couldn't use it except in some small pet projects. At the same time I was trying to understand Zope philosophy, which I never fully did.

In the beginning of 2006 I was freed from the shackles of corporate world. My aim was to become a Django guru, but before doing that, I decided to check out Ruby On Rails just so that I could compare the two.

After two years, I'm still working on Ruby and Ruby On Rails because I never really looked back at Python after discovering Ruby. I participated in an artificial intelligence/robotics project in Python last autumn - I have huge respect for Python but it's just not my choice of language.

Why is Ruby my choice of language? I guess it comes down to simpler syntax. Also, I think "one and one way only to do one thing" approach is good in many situations, but syntactical flexibility may also improve readability - if you take care to formulate your code so that it communicates the intent as well to the human reader as to the machine. I never did Perl and with all the horror stories I'm glad I didn't have to.

Admittedly the hype around RoR made it easier to stay on the Ruby platform (I'm a web dev mainly), but I still think Ruby > Python even if Python is the more stable and mature stack.

jacob said...

I'd venture a guess that java programmers tend towards the right brained... as a lot of them initially got into java as 'something different' to explore the wild west that was the internet.

My expirience has shown me that python is more logical, left brained, where ruby is much more artsy, like perl.

Ricster said...


Interesting thread... Never programmed in Java but have done C/C++. Was a true Pythonista until discovering Ruby and have since methodically migrated most of my applications to Ruby. I don't dislike the significant whitespace in Python nor do I think that its one-way philosophy is flawed, even if I never understood why there are two array-like data structures in tuples and lists.

However, the whole method_missing thing, variable interpolation, being able to magically extend classes that in other languages would be "sealed", etc., makes Ruby an interesting and fun language in the same way that playing with fire is interesting and fun.

On the plust side for Python, I do like SQLAlchemy more than ActiveRecord and think that Django is just as good as Rails... I also like list comprehensions and wish that these were implemented in Ruby also. But then again, Python does not have blocks and one-liner lambdas are not as useful as those found in Ruby, Groovy and even Lua.

What made me look elsewhere wasn't so much the advent of Rails but more so talk of seriously curbing some of the more functional aspects of the language in Python 3k.

blog said...

Are people that afraid of syntactical change?

YES! I need braces, but they are not needed in ruby. Ruby also has some other cool stuff that makes it attractive. IMHO its just more fun to write stuff in, although for a business it might makes sense to write in python for the forced indenting and better readability.

Also Rails is easier to learn than Zope.

Anonymous said...

Well, if you have a Python bias, then I suppose the following are clear to you:

* A primary goal of Ruby is to have more than one way to do things.
* Ruby programmers are more interested in being clever than writing readable, maintainable code.
* Rails' success is more due to marketing than to what it offers developers.

But for those of us who like Ruby, they sound a little like sour grapes. I've been to Ruby conferences and other events and read various Ruby blogs and mailing lists, and I rarely hear anyone say bad things about Python. In fact, people by far tend to be complementary towards Python.

Perhaps it's an artifact of a small sample size, but in these Python forums there's a real bitterness towards Ruby.

Ruby's underlying philosophy is not for there to be more than one way to do things. If you're curious it is spelled out explicitly by Matz -- to make programming fun. And he says that three primary contributors to making Ruby fun is to make it concise, consistent, and flexible.

Now perhaps an emergent property is to have more than one way to do some things. Some conditionals seem to be more naturally expressed using "unless" rather than "if", or some loops "until" rather than "while". But does that really make things more difficult to read?

Ruby is by no means perfect. But it has some very nice features and a syntax that many of us find pleasing.

banister friend said...


im not a partisan hack, i use ruby primarily , but i have alot of respect for python too.

one thing i dont understand however is how python users accuse ruby of having an arcane syntax. Ruby does use a couple of sigils, yes. but tell me, is:

@myvar (a ruby private instance variable)

really more ugly than:

self.__myvar (the same in python)

in my opinion the python equivalent is an eyesore; not the ruby.


Jonathan Ellis said...

That's just a difference in default behavior. It's more accurate to say, "in ruby, instance variables are written @var, but in python as self.var. In ruby, instance variables are always private and you have to write extra code to expose them publicly. In python, instance variables are public by default and you have to prepend __ to make them pseudo-private."

personally I don't find ruby's syntax particularly UGLY per se, except for a few perl-isms that I understand will be removed in 2.0. But I do find some aspects ('unless' statements and optional parens on method calls, for example) make ruby code less readable than the equivalent Python. (The optional parens mean that the hoops you have to jump through to get a reference to a method are clunky and somewhat obscure; in python, it's straightforward.)

banister friend said...

hehe, without wanting to prolong this too long, what 'hoops' are you referring to?

to get a reference to a method you simply go:
m_ref = myobject.method(:my_method)

and to invoke the method:

Why the call? because ruby uses functors.

Also, the optional parentheses was a deliberate design decision. to understand why check out the beautiful DSLs possible in ruby.

Also, there is not really any extra code required to expose private data members, just use the following in the class definition: attr_accessor :x
the private data member @x now has public getters/setters, a la c# properties. Also, 'unless x' is just syntactic sugar for if(!x), and not hard to understand at all.

JTP said...

One reason to prefer Ruby over Python is OO consistency. Guido broke Python's cherished "There should be one-- and preferably only one --obvious way to do it" with this:

len(object) vs. object.len()

Here is his reasoning:

I think that for certain things (e.g. len()) the functional notation is just more readable than the method notation, because it provides more information to the reader: len(x) guarantees to return an int. x.len() has no such guarantee, it could be an unrelated len method on an object that has nothing in common with sequences.

I personally find his reasoning to be unpersuasive in this case. Does this mean that methods that guarantee return of a particular object should be functional and others object oriented? I would greatly prefer only one way to find the length of an object.

Looking at the discussion in full
I think it is pretty clear his real reason was implementation-oriented and related to the time before Python was especially OO.

Yes, it makes a difference that a language was designed from the ground up to be object oriented. The clarity and consistency of Ruby's object heirarchy is proof of that.

To be sure, Python is a rock-solid, super sweet language with un-comparable libraries (numpy, matplotlib, etc.) [hats off to Guido and the entire community for such impressive work]. Still, the expressiveness of Ruby means that I can write cleaner, more concise code in Ruby that is not possible in Python (or so it seems to me). With everything Python has going for it, why else would I still choose to code in Ruby?? Rails-hype is why so many people tried Ruby. Ruby is why so many people still code in Ruby.

EricLewis said...

I am Java programmer and I prefer to use Ruby because ruby is helpful in big projects, It makes programming effort easy.