[Tutor] Properties of an object

Alan Gauld alan.gauld at btinternet.com
Fri Jan 30 20:05:40 CET 2009

"spir" <denis.spir at free.fr> wrote

> There is no real native support for ordinary OOP in python, meaning
> as is done in most other languages, or according to the theory.

I have to disagree. I think you are confusing OOP with C++ and Java.
The early OOP languages had a variety of approaches to this. Several
took the same approach as Python and ignored visibility of attributes
(Lisp & Object Pascal being obvious examples), others took the
other extreme of making all data "private" with no way to access
it other than via methods (Smalltalk being the prime example here)

The common terms for controlling access (private/public, and later
protected) didn't come along until C++ showed up in the mid 80's

And the theory of OOP is much less concerned about data hiding
(a technique championed by David Parnas at around the same
time OOP was being developed) than it is about the idea of
independant objects encapsulating data and functions within
a single entity or capsule. The most common theoretical models
were of each object being a separate process communicating
over message streams. Polymorphism was identified as a key
feature early on but even the idea of inheritance was later. Data
hiding was an orthogonaslconcept that happened to fit quite well
with the ideas of OOP but was not intrinisic to it.

So Python fits very well with basic OOP theory and practice,
its just quite different to C== and Java practice. But I would
strongly argue that neither C++ nor Java are particularly good
OOP languages - they have been compromised to facilitate
familiarity for most developers. Thats a very pragmatic approach
if you want to get a language adopted and has worked well for
both, but it doesn't mean they are very pure from an OOP standpoint!

> On the contrary, python is much more flexible. It lets you bind
> anything to an object, at anytime and from anywhere 
> (inside/outside):

And again is far from being alone in tyhe OOP world indoing that.
Languages like Lisp, Objective C and (I believe?) Actor all allow that

> On the other hand, there is a 'heavy' ;-) lack of structure,
> of frame, of standard, that easily lets code get chaotic

I've heard this claim many times but I have to say I haven't seen
it justified in practice. Of course you can write chaotic code but
in practice most developers just don't - its in their own interest to
play be the "rules".

> clear code, sensible structure only depend on the developer's 
> discipline.

This is true in C++ too.

Have you ever tried

# define private public
# include <someclass.h>

I've actually seen that in production code...

Python takes the consenting adults approach to these things,
but that doesn't mean its somehow ducking from the theory. In
fact, Guido has produced a language that is very close to a
Computer Scientist's vision of a pure imperative language
while still being practical enough to use in real world projects!

(Sorry for the rant but I get very frustrated when I see how the
C++/Java axis is polluting programmer's views of what
is/isn't real OOP!  OOP is a very broad church  :-)

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list