Ruby vs Python 2011

Yeah, that’s another debate about the pros and the cons of python and ruby. Many thinks it’s a false debate, you have just to give a try to both and see. I strongly disagree.

You cannot judge a whole language in a couple of hours, in a couple of days or even in a couple of weeks. Languages are complex, you have to learn the syntax and moreover and that’s maybe the most important part, the inhereted library which come with it.

For example, Ruby comes with great web/network related libraries (RoR, watir, webrat, anemone…) Hence, tools in the linux distribution BackTrace use Ruby as the lang of choice. In another side, Python has great libraries in stuff which use realtime environment, we can think about blender, games development, OpenGL, graphics interfaces…

Python has a huge support from Google, so it means a lot about the quality of the language. Nevertheless, the creator himself of Python now works for Google, so we can legitimetely question Google for its impartility about this subject. Ruby has direct or indirect support also from a lot of companies, but any of this campanies can compare to the size and the influence of Google.

Python and Ruby was created nearly at the same time and I think that the version number of the two languages reflected the underlined philosophy. Ruby’s current versions is 1.8.7 and 1.9.2. Python’s are 2.7 and 3.2. We can fully accept that’s for ruby, 1.X are major version whereas for python X.1 are the major version. So, for the same amount of time, Ruby have 9 “majors” versions whereas Python only 3. Yeah, I know it’s mean nothing about the quality of the language but it reflects a lot about the two language philosophies. Ruby move forward quickly and so does its community. Python works slowly but with far more strong support for each its version.

We can fell that in the language libraries. Python’s one tend to be more stable, less subject of changes, more robust and on another side Ruby’s one are more in the edge, with features been added, deleted and changed every time, and finally with better and simpler approach particularly with the ruby DSL which can make things pretty clear with a reading like natural english (: Rspec is a good example).

The downside of ruby is the inconsistency of the behavior between versions. This works for the core but also for its libraries. For example, core regex behaves in a different way in Ruby 1.8 and Ruby 1.8 with unicode strings. It can be very frustrating. Another thing frustrating is to make a extensive use of DSL, Ruby allows libraries and modules to pollute the global namespaces very easily and to monkey patch the core classes. It can be useful to have a to_json methods associated with every arrays but it can be painful when two libraries try to add to_json twice and their to_json do not behave in the same way. Python modules are simpler, prettier and they do not pollute the namespace. Unfortunately, Python miss tools like rubygems and bundler to make the management of modules very easy and consistent.

Back to the beginning of the post, it’s not easy to choose between this two great languages. On the other hand, you cannot waste your time rewriting your application in both to see what fits best. My opinion is simple. Python is a language to talk to the computer. Ruby make the computer able to talk to you. Python takes a academic approach trying to do the right things at the right point. Ruby try to fill the hole between humans and computer.  Good or Bad ? Who can tell ? If you want a stable approach learn Python. If you like to gamble, bet Ruby.