Matz, who invented Ruby, said that he designed the language to be more object-oriented than Python. How is Ruby more object-oriented than Python?
Python is generally better for educational use or for people who want to build quick programs rather than work as developers, while Ruby is better for commercial web applications. There are more specific differences when comparing Ruby versus Python, and they have in common that there are many ways to learn both.
Ruby is a pure object-oriented language and everything appears to Ruby as an object. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false. Even a class itself is an object that is an instance of the Class class.
We know that Ruby defines everything as an object including all predefined and user-defined types. It is a pure object-oriented language. Java does not fall under this category because of the eight primitive types (byte, short, int, long, float, double, char, and boolean) that are not classified as objects.
If you take the Python from 1993 and compare it with Ruby then the latter is more object oriented. However, after the overhaul in Python 2.2 this is no longer true. I'd say that modern Python is as object oriented as it gets.
One example that's commonly given is len
, which in Python is a built-in function. You may implement a special __len__
method in your objects which will be called by len
, but len
is still a function. In Ruby, objects just have the .length
property/method so it appears more object oriented when you say obj.length
rather than len(obj)
although deep under the hood pretty much the same thing happens.
That said, over the years Python have moved towards more object-orientation. Currently all objects (and implicitly user-defined objects) inherit from the object
class. Meta-classes have also been added, and many of the built-in and core library classes have been organized into hierarchies with the help of ABCs (Abstract Base Classes).
In my heavy usage of Python I have never found it lacking in the OO department. It can do everything I want it to do with objects. True, Ruby feels somewhat more purely OO, but at least in my experience this hasn't been a really practical concern.
From WikiVS,
… where in Ruby all functions and most operators are in fact methods of an object, a number of Python functions are procedural functions rather than methods.
The following interview with Matz, the creator of Ruby, provides additional context to your question and the point above.
…
Stewart: Let's start with a little history. Why did you decide to write Ruby?
Matz: Back in 1993, I was talking with a colleague about scripting languages. I was pretty impressed by their power and their possibilities. I felt scripting was the way to go.
As a long time object-oriented programming fan, it seemed to me that OO programming was very suitable for scripting too. Then I looked around the Net. I found that Perl 5, which had not released yet, was going to implement OO features, but it was not really what I wanted. I gave up on Perl as an object-oriented scripting language.
Then I came across Python. It was an interpretive, object-oriented language. But I didn't feel like it was a "scripting" language. In addition, it was a hybrid language of procedural programming and object-oriented programming.
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.
…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With