is python Object oriented??
mdw at distorted.org.uk
Mon Feb 2 21:14:49 EST 2009
"Russ P." <Russ.Paielli at gmail.com> writes:
> I am not sure why people keep "mentioning" that "Python is not Java."
> As a slogan, it is rather misleading. Python is not C++, Ada, or Scala
> either. All of those languages have enforced access restriction. Why
> only mention Java?
Because Java is a well-known member of a family of object-oriented
languages (or at least languages supporting object-oriented
programming). `Python is not Java' is somewhat of a slogan, intended to
convey the message that Python, quite intentionally, does not behave in
the same way as other languages you may be familiar with.
Smalltalk's visibility features are very different from C++ and Java: a
method can mess with its own object's (i.e., the recipient of the
message which caused the method to be invoked) instance variables but no
others -- a restriction enforced syntactically, since there is simply no
way of referring to a different instance's variables. There is no
restriction whatever on sending messages to other objects. Self
abandons the concept of instance variable (and of class, for that
matter), and access controls with it.
The Common Lisp Object System provides no access control features
(though one could probably implement some using the MOP, were one
sufficiently motivated); however, CL's package system is better placed
for this job anyway. Other object systems for Lisp-family languages
tend to be similar. The Lisp Machine's Flavors -- the first object
system with multiple inheritance -- relied on the package system for
access control; CLOS-like systems for Scheme, which lacks packages, tend
not to bother at all. (The package system controls the mapping from
tokens read from, say, files to symbols; packages can export some of
their symbols, so you can refer to, say, MDW:FOO if package MDW exports
symbol FOO, or you can `use' package MDW in your own package to make FOO
refer to MDW:FOO. The package system tries to keep you honest rather
than acting as an enforcement mechanism: even if MDW doesn't export BAR,
you can still talk about MDW::BAR -- note the double-colon -- as much as
you like. Working at the name-to-symbol level allows the package system
to operate uniformly on all the various namespaces in Lisp.)
Perl's object system provides no access controls. Ruby does, following
Simula, though it uses C++-ish `private' for Simula's `hidden'.
> If that's the case, you have my sympathies, but let's not pretend that
> Java is the only popular OO language with enforced access
No, but let's not pretend either that such features are essential to
object orientation, or that they are even typical of object systems
outside of a particular (admittedly popular) subfamily.
More information about the Python-list