Miscellaneous design and Python use questions

Gordon McMillan gmcm at hypernet.com
Thu Feb 17 23:22:54 EST 2000


Travis B. Hartwell wrote:

> I suppose my questions here are geared to Python as it is used in a
> large project -- more than a script of ~200 lines.
> 
> 1)  When I do a typical OO-design with C++, I pay a lot of attention
> to information hiding.  I.E., I keep all of the data members private
> and rely on get/set functions to use them.  I feel that this is a good
> practice.  But, with Python, we don't have the access issue.  I still
> believe that information hiding is a good idea.  From the experienced
> Python developers, is it practice to use such functions within your
> classes?  Or do you just access things directly?  What are your
> thoughts on style regarding this?

I think most people would agree that distinguising external and 
internal methods is important, and that attributes should 
generally not be accessed directly. Note that you can turn the 
problem on it's head and make an attribute access into a 
method call (using __getattr__ and __setattr__).

You'll probably be happier if you stop thinking in strict OO 
terms, and realize that Python is all about interfaces, and 
interfaces are implicit (no need to inherit from some particular 
base class). To paraphrase Aahz: loosely couple, and 
componentize the hell out of everything.

> 2)  I am planning using Python embedded in one of my applications --
> using C++ Builder for the GUI development and speed-critical
> portions.  For the rest, I would prefer to use Python just because I
> have become accustomed to its power.  But, I have been having a few
> road-blocks in this plan for embedded Python.  I guess I'm having a
> hard time visualizing exactly where to have the 'dividing line'
> between C++ and Python and in designing the interfaces between the
> two.  What are some general hints in designing applications using
> Python as the engine and C++ as the front-end?

Write it all in Python first, then decide if you need any C++. I 
say that as a long time C++/Java/C/.../IBM S370 assembler 
programmer. Even if you don't use any Python, you'll still save 
time, because you'll have a model that works.

- Gordon




More information about the Python-list mailing list