56
votes

I want to know why Python is not fully object-oriented. For example, it does not support private, public, protected access level modifiers.

What are the advantages and disadvantages of this? By these expressions, Python is suitable for what applications (Desktop, Scientific, Web or other)?

7
Python is suitable for nearly everything, that doesn't rely on hard number crunching, but even then you can write these Parts in C. Encapsulation isn't that useful in a dynamically typed language. It only aides the compiler, even in Java you can(and sometimes need to) circumvent it via reflection. Encapsulation, IMHO, doesn't add any security, it just gives you the feeling that there is more security in place. - Ivo Wetzel
@extraneon : No , just for know . @Wetzel : I agree with you on ' Encapsulation isn't that useful in a dynamically typed language '. - Mahdi Amrollahi
Python is "full object oriented". "Object oriented" was a term coined, rather than defined by some language, such as Java. It is a computer theory. Python simply does it differently, but for good reasons. "Features" such as the ability to make attributes private have nothing to do with the utility of a language and everything to do with the subtle enforcement of good practices when using the language. - orokusaki
@orokusaki I know it's been 5 years, but... "the ability to make attributes private" is what computer theory calls Encapsulation and is one of the 3 pillars of OO. Now: is it still true that Python does not have "private", or has this changed? - Irina Rapoport
@ТаняТ. I'm sorry to have to inform you that your professor might have let you down. Please just take a peek at en.wikipedia.org/wiki/… and note the key phrase, "one of two related but distinct points", just before the two bullet points nearest the top of that page. - orokusaki

7 Answers

93
votes

Python doesn't support strong encapsulation, which is only one of many features associated with the term "object-oriented".

The answer is simply philosophy. Guido doesn't like hiding things, and many in the Python community agree with him.

44
votes

Guido once said that "we are all consenting adults here". Here's the longer explanation from long ago: http://mail.python.org/pipermail/tutor/2003-October/025932.html

There's an agreement that underscores mean private elements and you should not use them. Unless you know what you're doing and you really want to.

The link also mentions another way to put it in case of Perl:

"a Perl module would prefer that you stayed out of its living room
because you weren't invited, not because it has a shotgun."

13
votes

Access modifiers (public, private, protected, etc) are not required for class-based programming. They are just a feature, like multiple inheritance.

3
votes

I think Python is designed to be a hybrid. You can write in object oriented or functional styles.

The hallmarks of object-orientation are abstraction, encapsulation, inheritance, and polymorphism. Which of these are missing from Python?

Object-orientation is a continuum. We might say that Smalltalk is the purest of the pure, and all others occupy different places on the scale.

No one can say what the value of being 100% pure is. It's possible to write very good object-oriented code in languages that aren't Smalltalk, Python included.

Python is useful in all those areas: scientific (NumPy), web (Django), and desktop.

2
votes

I believe Python is more of a very practical, pragmatic language.

Concepts which offer value to the developer are put in, without too much consideration about theological concepts like "proper OO design" and stuff. It's a language for people who have real work to do.

I think Python is suitable for all kinds of environments, though Desktop is a bit difficult due to the lack of a single framework. For all applications it's handy to use a framework, like NumPy for computational stuff, Twisted or Django for web stuff, and WxWidgets or other for Desktop stuff.

2
votes

What exactly is full object oriented? Alan Kay said "Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind.". Admittedly, he probably did not have python in mind either, but it is worth noting that Smalltalk also protects classes by convention, no mandate.

-5
votes

A language is said to Full Objective Oriented if it has no primitive data types. Each data type we need to construct.