Singleton classes (with no such thing as static variables)

Georg Lohrer GeorgLohrer at gmx.de
Mon Jul 2 12:05:10 EDT 2001


On Mon, 02 Jul 2001 11:45:24 +0100, Giles Constant
<gilesc at hyperlink-interactive.co.uk> wrote:

>Hi there,
>
>Being a C++ head, it's probably more a problem with my design than a python 
>problem, but I figured you guys would be able to help.
>
>I'm trying to make a class called "Environment" which will store some 
>global data such that all instances of the class have access to it.  The 
>alternative is to create a single instance and pass it around every single 
>object in the entire project, but it gets used so frequently that it would 
>be rediculous.
>
>Is there a way of doing this, or do I need a new paradigm? :-)

Maybe the latter one. I'm also an old fellow with C (over 15 yrs) and
C++ (8 yrs) and I like sophisticated stuff (like Guru-of-the-week,
etc.). But starting Python a year ago I've to throw away some of my
current point of views. Sometimes because they are not common or even
possible in Python or because I misunderstood the patterns of a
interpreted language like Python.

Oh, you could realize most of good object patterns in Python, too. But
if it is necessary or even sensefull, it seems to be doubtful, because
the concept and the paradigm of an interpreted language is really
different. 
But, to be honest, it's more a feeling of getting a successfull
approach towards a solution with Python. Two days ago, I reviewed some
three months old code (rather running fine and correct) and I
eliminated a lot of stuff and replaced it with more Python-like code
(the old one was a more or less C++-to-Python translation) and the
code runs faster and it spends a better feeling seeing the code (if
you understand what I mean -- if you see a graceful piece of code in
your favourite language it will be well-formed and you could see/feel
it.)

BTW, currently I'm doing half of my work in C++, the rest in Python,
and I everytime like the return to Python. But I really "hate" the
effective cycle of editing-running-debugging-editing. Sometimes there
is a melange of all these things -- I've never had this ever before --
and it's marvellous. My speed of producing correct code was doubled,
but with compiler-languages you always have some time for relaxing
(during compilation/linking), but with languages like Python its away
:-((
 So, after one or two hours of pythoning, I need a rest for getting
some relaxation.

Like now,

Ciao, Georg



More information about the Python-list mailing list