Is Python's Object Orientation Retrofit?

When I said that somewhere, I was hit for some reason.

Python is an object-oriented programming language.

First, the above is mentioned as a premise. Python had object-oriented features when it was first released. This is very different from Perl and PHP, which were retrofitted with object orientation in the version upgrade after the initial release. However, I would like to clearly claim that it is a retrofit.

Object-oriented is not a retrofit = "pure object-oriented programming language"

Wikipedia describes the concept of "pure object-oriented language". [Wikipedia-ja: Object-oriented programming](http://ja.wikipedia.org/wiki/Object-oriented programming) and [Wikipedia-en: Object-oriented programming] See both (http://en.wikipedia.org/wiki/Object-oriented_programming). I don't think the definition is slightly different between the Japanese version and the English version, but the Japanese version is cleaner. In other words, the word "pure" is used depending on whether it was designed as an object-oriented language from the beginning.

What else will it be? In other words, it is a language in which object-oriented is added later to the language design that is not object-oriented. Not being a "pure object-oriented programming language" means that object-oriented is __ postscript __. The Japanese version defines such a thing as a "hybrid object-oriented language".

Unfortunately, Wikipedia mentions Python as one of the object-oriented programming languages, but doesn't give it as an example of "pure" or "hybrid". Even though it covers Ruby, which is minor than Python.

Just because it's available at the time of the first release doesn't mean it's not a retrofit.

Notable in the Wikipedia article above is that C ++ is "hybrid". C ++ is a language that extends C with object-oriented programming and so on. Of course, when C ++ was first released, it was an object-oriented programming language.

So you can't conclude that it's not a retrofit just because Python was object-oriented when it was first released.

Notable is the initial design before release

A keen reader will point out the decisive difference in the origins of the C ++ and Python languages here. C ++ was created in the form of an extension of C. So it's okay to claim that C is object-oriented __ retrofitted __. But Python is not an extension of any other language. Of course, I refer to and are influenced by other languages, but there is no underlying language. It is a language designed from scratch.

However, it seems that Python did not adopt object orientation at the initial design stage. In short, it wasn't an object-oriented programming language in the early days before its release. After that, it was _ retrofitted with object orientation __ and then released to the public. The basis for this story is only Exploring other languages for Rubyist [Part 1] Python written by the author of Ruby. I thought the credibility was suspicious, but the Python author himself The History of Python: Adding Support for User-defined Classes -for-user-defined-classes.html) (Japanese translation: The History of Python.jp: Addition of support for user-defined classes -post_30.html)) talks about its historical background. [^ 1]

[^ 1]: thanks: @shibukawa

Next, I would like to mention the non-object-oriented part that is evidence of retrofitting.

Where Python isn't object-oriented

Python is a language that can be used as an object-oriented programming language, even if it is retrofitted. Similarly, retrofit C ++ can be used as an object-oriented programming language. So the claim that it can't be used object-oriented because it's a retrofit is __ totally nonsense __. Python was pretty early and neatly adopted, which sets it apart from languages like Perl and PHP that have a dirty retrofit.

However, there are some things that are not object-oriented because they were not designed as an object-oriented programming language from the beginning. I would like to compare it with Ruby, which was designed as an object-oriented programming language from the beginning.

Have a function

Python has functions. Convenient and frequently used functions (such as the print () function that outputs characters to standard output and the len () function that calculates the length of an array, etc.) are built-in and provided from the beginning. Functions aren't object-oriented because they aren't methods associated with any object.

Conversely, Ruby has no functions, only methods. Since Ruby has a language design that the existence of the implicit top-level object main and self can be omitted, the Kernel # puts method etc. can be written like a function, but strictly speaking, self (top of the code) In the case of a level, it just calls the method of the top-level object main).

There was an old style class with restrictions

There were two types of Python classes. The old style class that was used before 2.1 and the new style class that can be used from 2.2. In the old style class, built-in types cannot be inherited, type and class management are separate (for objects ʻaandb of two unrelated classes, type (a) == type (b) `is truly There were some problems such as (may be), and the language as a whole was not object-oriented. In the new style class, the class has been redesigned from scratch (but the writing style is almost the same), and it is satisfying as object-oriented.

In Python3, only the new style class is available, and the old style class is abolished.

On the contrary, in Ruby, only classes exist, and since all classes are treated the same, there were no built-in types (classes) that could not be inherited.

Python is still an object-oriented programming language, but it's not the only one.

Since Python has been extended for a long time, there are some parts that are not very beautiful as a language. Python3 organizes those parts, and Python3 is a great language. Even when viewed as an object-oriented programming language, it has functions and elegance comparable to those of a "pure object-oriented programming language" because it has been integrated into a new style class.

Finally, although it is a little old, I would like to introduce this article.

Methane's blog: Why len remains a function in py3k

So it doesn't matter to Python that it's an object-oriented programming language. Of course, it is important to be able to do object-oriented programming, but it is thought that the language itself does not have to be bound to object-oriented programming. Python has the image of binding coding, but it is actually a free language that is not bound by object orientation.

Since Ruby is a "pure object-oriented programming language", it can only be programmed in an object-oriented manner (although it can be forced, there is almost no advantage in using Ruby). It's easy to think that Ruby inherits Perl's freedom, but it may be ironic that you can't escape the object-oriented bindings.

Recommended Posts

Is Python's Object Orientation Retrofit?
Where is python's fluentd??
What is Python's __init__.py?
TypeError:'int' object is not subscriptable
[Django error]'RenameAttributes' object is not iterable
Why is Python's logging library camelCase?
Is Python's static scope messed up?