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.
Comments
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...
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)
My apologies, shouldn't post past my bedtime.
"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...
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 ...
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.
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.
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.
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.
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 mentioned Jython. They counter by saying Ruby has something similar. Even though I'm not sure they're correct.
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.
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.
My expirience has shown me that python is more logical, left brained, where ruby is much more artsy, like perl.
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.
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.
* 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.
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.
thx
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.)
to get a reference to a method you simply go:
m_ref = myobject.method(:my_method)
and to invoke the method: m_ref.call
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.
len(object) vs. object.len()
Here is his reasoning:
[blockquote]
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.
[/blockquote]
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.