Python or Ruby?Posted: June 27, 2011
Looking out for something new, something unconventional I came across the other side of what one is taught academically, those programming languages which have their own domain, their own community. But if you wanted to get your hands on one of those lethal weapons of programming, which one would it be?
So LET the battle begin…
On common grounds: Python and Ruby
Ruby and Python, both are multi-paradigm programming languages. Both being high level, dynamically typed and garbage collected. Having an interactive shell, standard libraries and persistence support(Well, we’ll talk about support later again).Though both are said to be multi-paradigm, the essence of object oriented concept is seen more in ruby as it is inherited from Small Talk and Perl language. Every data type, the ones that were described as primitive and the classes are objects. The variables are all references to those objects. The functions are methods which always call on an object.
Python evolved before Ruby in 1989 from ABC programming languageand was created by Guido Van Rossum. Ruby was conceived on February 24, 1993 by Yukihiro Matsumoto (Matz) in Japan.Matsumoto has stated, “I wanted a scripting language that was more powerful than Perl, and more object oriented than Python. That’s why I decided to design my own language”.
Some aspects of Ruby might be uncomfortable to the orthodox programmer who has been working on C, C++ or such for a long time. The way Ruby has its philosophy is quite surprising still its founder clains it to follow “Policy of Least Astonishment(POLA)”, “Everything Is An Object” and “There Is More Than One Way To Do It”. The last is highly contradicts one of the principles of Python, which says “there should be one—and preferably only one—obvious way to do it”. The core philosophies of python are stated in The Zen Of Python. I didn’t go into much technicality in describing how the above stated principles are followed.
Python was designed to be highly extensible so that it can be used in varied ways which makes it possess a small core. Python is easily used on different frameworks and most popularly with Django. Other Web application frameworks like Pylons, TurboGears, web2py, Flask and Zope are highly supportive in making python further powerful in the field of application development. NumPy, MatploLib and SciPy libraries make it a scientific computing language.
Even Ruby has become popular when used on its popular framework Rails.It has been credited for making Ruby “famous”. Other popular alternative implementations of Ruby are IronRuby, MacRuby, JRuby.
Ruby over Python
Honestly, I couldn’t find many a points to allow Ruby to take over Python and this gives a bit hint to you on who might be the winner at the end.The best thing about Ruby is the composability of the language. The semantics make it easy and clear to read the code.Let this image say everything:
Above is a code written for a game in which, when a new player is added, has 100% health. The first block of code is written in Ruby and the other one in Python.As we can see, the ruby code describes in simple English as to what is going on. While the python code is, comparatively a little difficult to understand by a non-programmer.
Python over Ruby
Lets begin with the beginners. Python was made with a mission to be simple for beginners. Leave a beginner with python and ruby and he is sure to find python easier, unless he is from a perl background.
Lets get back to the community. Python has a larger number of users and developers, therefore a larger community which provides support along with the large number of books, tutorials, wizards, tools and libraries.However, the Ruby community is claimed to be more friendly and nice.
The syntax of python is rigid unlike that of ruby, in which one task can be accomplished in several ways. This can be a trouble when the code is being read or studied. However, this aspect is absent in python. Also the code of ruby consists of many monkey patches, which are also somewhat confusing. Special cases in the code, irregular coding practices are some of the glimpses we get in ruby’s code.
Python has a much greater range of libraries available to it, and most of those libraries are more mature and better documented than their Ruby counterparts. Also, there is a perception out there that the Ruby standard library is smaller but better organized than the Python one.
I’d agree that threads are simple in Ruby. But the performance seems lower than the standard Python built-in threads, and much, much lower than either Python generator threads or the threads that Stackless Python provides.
The Final Verdict
There is not a thing to say as one language could be better than the other, each has its own place.This is how the founder of Ruby puts it:
Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, ‘I was surprised by this feature of the language, so Ruby violates the principle of least surprise.’ Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me.
Ruby community loves its language and so does the Pythians their language. It all depends on what you love to write in.