[Tutor] Private and Public variables

Erik Price erikprice at mac.com
Tue Oct 7 22:58:25 EDT 2003


On Monday, October 6, 2003, at 10:06  AM, Gonçalo Rodrigues wrote:

> I tend to make this "mistake" a lot. I started using Python when
> Python 2.2 came out, when, in particular, properties became available.
> My experience was mostly in Java where I really was paranoid about
> data hiding. These Java habits were carried along and made their
> imprint on my Python code, but what's more important, after 2 years
> they are still with me. I think one of the reason's why is because I
> tend to favor (following the gang of 4) composition to inheritance. As
> such, it is very important that my classes have clean and small
> interfaces, leaking as little as possible to the outside world. These
> interfaces should also be "recognizable", e.g. they follow the
> interfaces of the Python objects as much as possible. A simple
> example: whenever I have an iterable container that I want to make
> mutable I had methods:
>
> def append(self, elem):
>     """Append an element."""
>     <whatever>
>
> def remove(self, elem):
>     """Remove an element."""
>     <whatever>
>
> So, what do you guys think?

I am the exact same way.  Also a Java programmer primarily (who covets 
Python and is attempting to convert his cow-orkers from Perl), I 
definitely use too many getters and setters in Python due to Java 
habits.  And I also tend to use a lot of delegation and composition, so 
I end up masking everything behind an interface.  Basically I need to 
learn to relax more when I'm using Python.


Erik




More information about the Tutor mailing list