OO in Python? ^^

Alex Martelli aleax at mail.comcast.net
Sun Dec 11 12:50:48 EST 2005


Matthias Kaeppler <void at void.com> wrote:
   ...
> I'm so used to statically typed languages that the shift is very 
> confusing. Looks as if it isn't as easy to learn Python afterall, for
> the mere reason of unlearning rules which don't apply in the world of
> Python anymore (which seem to be quite a lot!).

If you start your reasoning with Java for most aspects (and with C++ for
just a few) it may get easier -- for example, garbage collection, the
semantics of assignment and argument passing, as well as the
immutability of strings, are very close in Java and Python, and they're
such a "bedrock layer" parts of the languages that IMHO they're more
likely to be stumbling blocks if you "think C++" rather than "think
Java", while learning Python.

If you can imagine a Java program where everything is declared to be
Object, all method calls have an implicit cast to "some interface
supplying this method", and all class declarations implicitly add many
"implements IMethodFoo" for automatic interfaces supplying each of their
methods foo, you're a good part of the way;-).  Such a style would be
unusual (to say the least) in Java, but it's clearly POSSIBLE... it's
actually not that unusual in Objective C (except you say ID rather than
Object, and implicit interfaces ARE sort of there) -- the main caveat i
would give to an Objective C person learning Python (besides the garbage
collection issues) is "in Python, you cannot call arbitrary methods on
None and expect them to be innocuous noops" (like in Java or C++,
calling anything on None, aka a NULL pointer aka null, is a runtime
error in Python too; the language without this restriction in this case
is Objective C!-).


Alex



More information about the Python-list mailing list