inner classes in python as inner classes in Java

Carlo v. Dango oest at soetu.eu
Thu Oct 16 04:03:19 EDT 2003


On Wed, 15 Oct 2003 21:52:32 GMT, Alex Martelli <aleaxit at yahoo.com> wrote:

> You'll have to decide what semantics you want to obtain when an
> attribute is set on an instance of the "inner class" -- I sure can't do
> it on your behalf.

I want the semantics of java's inner classes and the semantics of inner 
methods... that the inner class shares the fields and methods of its outer 
class instance.. But I've come to realize I can't do this in python, as 
the statement in some method in the inner class "self.i = 42" can be 
interpreted as "create i in the inner class instance" or "lookup i in the 
'outer scope' and set it"



> There's a reason the official Python style guidelines have been
> amended to prefer spaces instead of tabs, you know.  Sure, there
> will be some programs who display tabs in a way compatible with
> your preferences, but others won't; be conservative in what you
> generate -- spaces are ensured to be displayed as you intend, tabs
> are NOT, so don't use the latter in any code you send to others.

hmm depends on which font people are using.. if it's not monospace, the 
layout will also change.. I doubt that there are many news readers where 
you cannot set TAB == 4 spaces




>> actually its forwarding or consultation, as self is re-bound when you
>> invoke the outer..
>
> In your Python code (and mine), it is false that "self is re-bound"
> (only an instruction such as "self = ..." would do that, and there is
> no such instruction in that code).  Sure, when a method A of
> object B calls a method X of object Y, the local name 'self' is
> bound to Y in the execution of X while the same name is bound
> to B in the execution of A.  But that is not re-binding -- just the
> distinction between lexically-same names in different scopes.

well, I disagree... there is a difference between virtual and non-virtual 
methods. The first does not re-bind self, when doing super calls or when 
casting an object to some super class and invoking methods on it (like 
using C++'s :: )


> Anyway, the term "delegation" is common for the operation in
> question - it is for example used in the "gang of 4"'s Design
> Pattern book.

well, 'delegation' is cited in OOPSLA, ECOOP, AOSD etc litterature of 
being defined in the seminal 1986 OOPSLA paper "Using Prototypical Objects 
to Implement Shared Behavior in Object-Oriented Systems" by H. Lieberman. 
the GOF book came out around 9 years later.


Carlo

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/




More information about the Python-list mailing list