tags:

views:

302

answers:

7

I want to know , why Python is not full object-oriented ? (e.g : Does not support private , public , protected) . What`s the advantage and disadvantage of this ? By this expressions , Python is suitable for what applications (Desktop , Scientific , Web or ...) ?

Thanks .

+1  A: 

it does support public and private.

See http://diveintopython.org/object_oriented_framework/private_functions.html ,found from 5 seconds on google.

Sirex
That's not really private, in the normal OO sense. It's just obfuscated. The call `m._MP3FileInfo__parse("/music/_singles/kairo.mp3")` would work just fine.
Marcelo Cantos
true, but it has the concept of avoiding casual calling to functions youd rather disallow
Sirex
C++ private isn't private either. Some easy pointer manipulation and you can work around anything.
Matt Joiner
@Matt: not without invoking undefined behaviour.
Marcelo Cantos
@Sirex: The `__` prefix is like a sign saying, "Staff only". The concept of "private" is more like a padlock.
Marcelo Cantos
@Marcelo: I prefer the analogy to those velvet rope dividers at the theater.
Paul McGuire
+10  A: 

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.

Marcelo Cantos
+1, the right answer. Though I'd say: Python doesn't *enforce (information hiding/encapsulation)*. obj._field is "private" in that idiomatic python code won't access it unless necessary (dir() function, reflection, serialization, having to hack around limitation of legacy code which can't be changed).And Python is more OO than e.g. Java or C++ or C#, as there are no primitives.
delnan
@delnan: You're right; Python doesn't enforce hiding/encapsulation. It also doesn't *support* hiding/encapsulation any more than C does. In fact, with no reflection, C supports hiding better than Python! :-)
Marcelo Cantos
+1  A: 

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.

duffymo
+2  A: 

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.

extraneon
There's actually a hell lot software for GNOME that's written in Python, I've written a 11k lines one myself, the code is just incredible readable and maintainable, development is also really fast and there are bindings for nearly everything. But I have to admit that GTK is really cumbersome at times.
Ivo Wetzel
+8  A: 

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."

viraptor
+1 for the quote, I like that.
Davy8
+2  A: 

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

Daniel Vassallo
+1  A: 

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.

deinst