Python was introduced in 1991 by Guido Van Rossum as a high level, general purpose language. Even today, it supports multiple programming paradigms including procedural, object oriented and functional. Soon, it became one of the most popular languages in the industry, and in fact is the very language that influence Ruby and Swift. Even TIOBE Index reports mentions python as the third most popular language in the world today! And mind you, this popularity has very less to do with Monty Python and more with the standard libraries that help a programmer do anything and everything in merely a few lines of code.
Python was introduced in 1991 by Guido Van Rossum as a high level, general purpose language. Even today, it supports multiple programming paradigms including procedural, object oriented and functional. Soon, it became one of the most popular languages in the industry, and in fact is the very language that influence Ruby and Swift. Even TIOBE Index reports mentions python as the third most popular language in the world today! And mind you, this popularity has very less to do with Monty Python and more with the standard libraries that help a python programmer do anything and everything in merely a few lines of code.However, a large community of programming language enthusiasts have called python a ‘hybrid’ or ‘partially object oriented’ in nature. While python’s fame is accredited to its object oriented properties, why do some claim it is not even an OOL/OOP? Before we dive deep into this, let’s take a look at what an Object Oriented Language truly is.
What is an Object Oriented Language?
As the name suggests, Object Oriented Programming Language or an Object Oriented Language is all about objects. It realizes real world entities like inheritance and polymorphism in programming. For this, it uses object instances of a class, whereby a class is the building block of such a language. The main concept behind introducing OOP was to bind data and functions into one unit so that the outer world cannot access private data – something called encapsulation and abstraction.
The main concepts of an object oriented programming language are:
- Polymorphism: Using the same name for multiple functions.
- Encapsulation: Binding data and functions as one unit.
- Inheritance: Using functions of a preceding class.
- Abstraction: Hiding data and sharing functions.
- Classes: Groups of different data types and the functions to access and manipulate them. It is An user defined prototype of an object.
- Objects: Instances of the class, things you can Operate on.
And this is exactly where the dilemma with python arose. Python does not support Encapsulation – a very important component of Object Oriented Programming!
Why is Encapsulation not supported in Python?
Strange as it may be to hear, the idea of encapsulation not being supported in Python has philosophical roots. People believe Guido did not think hiding data was necessary. He believed in sharing data just as you would share your functions. Long ago, in an explanation, Guido said, “we are all consenting adults here”.
It is worth noting that the creator of the term OOP, Alan Kay, said, “Actually I made up the term “object-oriented”, and I can tell you I did not have C++ in mind.” So it is secure to consider he did not have python in his mind either. While python trusts its maker, it also trusts its editor. So yes, there are no access specifiers in python and you can go around poking in the dark.
However, if it is absolutely necessary to hide data, python does give you an option. Putting underscores identify the literals as private and put out a message that one shouldn’t use them.
Guido must have removed encapsulation, but it is time we appreciate him for introducing indentation. As a programmer, you must have come to believe that encapsulation only gives you a ‘sense of security’ than actual security. Here, indentation provides actual readability to the code. He removed a not-so necessary feature but introduced hundreds of powerful ones to take its place. It is time we appreciate those.
‘Pure’ object oriented language
One can argue and say that Smalltalk, the first ever object oriented programming language, is the only Object Oriented programming language. However, in all honesty, object orientation is really continuum. If Smalltalk is the purest of them, others lie on varied scales. Python, for example, can score less due to lack of encapsulation. And even if Python is not a 100% pure object oriented language, one can write programs that work better in it – programs that sometimes don’t work for Smalltalk at all.
So is 100% object orientation actually desirable? That is indeed a contemplatable question.
Final Verdict
Looking at facts and figures, we can start with the assumption that python is an ‘object based language’ as it has proper classes defined. A very simple example would be
a = 10
Here, 10 is an object and hence belongs to a class. The class in this case is ‘int’. You must now be thinking of Java where ‘int’ is a primitive data type. But, surprisingly, ‘int’ is a class in Python – a commendable approach towards object orientation.
Coming back to our definition of an Object Oriented Program, it is a programming language that uses classes and objects to manipulate data and apply real-world entities like inheritance to them. Since python is fully capable of doing this, it definitely qualifies.
Yes, Python is an Object Oriented Programming Language
You can carry out inheritance, polymorphism, and can make hundreds of objects of a class. Python is a multi-paradigm language, a language that has been Object oriented since the day it existed. However, its efficiency completely depends on your code.
Python has come a long way from Smalltalk or even Java, but the changes have all been for the better. If you remember to be DRY (Don’t Repeat yourself) and shy (don’t poke into unnecessary functions), your code will be efficient, no matter what the language is.
Read more Sources:
https://www.tiobe.com/tiobe-index/
https://en.wikipedia.org/wiki/Python_(programming_language)
https://mail.python.org/pipermail/tutor/2003-October/025932.html
Great topic to dive into. I’d say Python is object-oriented to a large extent, but it also supports other programming paradigms like procedural and functional programming. While everything in Python is an object, it’s not purely object-oriented like Java or Smalltalk. Python allows for things like functions and variables that aren’t tied to specific objects, which gives it a bit of flexibility beyond strict object-oriented principles. It’s this flexibility that makes Python such a versatile and widely-used language. What are your thoughts on this?