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.

22 comments:
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...
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)
Make that "You're right...".
My apologies, shouldn't post past my bedtime.
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...
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.
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 ...
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
http://yozzeff.blogspot.com/2004/12/choosing-scripting-language-for-jvm.html
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.
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 foo.bar. 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.
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.
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.
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.
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.
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.
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)
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.
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.
Baah!
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.
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.
I'm wondering the same thing. Why do so many Java developers only see Ruby? There's the Groovy language (http://groovy.codehaus.org) 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.
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?
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.
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.
Post a Comment