Is this possible in Python ?

Jay Braun lyngwyst at aol.com
Fri May 16 20:42:33 EDT 2003


"Helmut Jarausch" <jarausch at igpm.rwth-aachen.de> wrote in message news:<3EC38453.1090104 at igpm.rwth-aachen.de>...
> Carel Fellinger wrote:
> > On Thu, May 15, 2003 at 10:03:55AM +0200, Helmut Jarausch wrote:
> > ...
> > 
> >>Given a program with assignments like
> >>a=b+a
> >>one can say either
> >>monitor 'a' on the left
> >>or
> >>monitor 'a' on the right.
> > 
> > 
> > In python2.2 and up you can encapsulate such behavior in a class:
> > 
> >     class C(object):
> >         def __init__(self, a=0):
> >             print "init a"
> >             self.set_a(a)
> > 
> >         def get_a(self):
> >             print "right-monitor-a"
> >             return self._a
> >     
> >         def set_a(self, value):
> >             print "left-monitor-a"
> >             self._a = value
> >     
> >         a = property(get_a, set_a, None, "monitor a")
> > 
> >     b = 1
> >     c = C()
> >     c.a = b + c.a
> 
> Thanks for this reply.
> 
> But it doesn't solve the problem.
> The trick in Simscript was
> 
> You just write
> a= b+c
> d=2*a
> 
> then some time later you want to monitor the variables,
> e.g. for debugging
> and with changing any source line
> you just enter these monitoring functions and
> activate them.
> Then whenever 'a' is accessed that's recognized
> and these monitoring functions are invoked.

As one who makes a living writing Simscript programs (yes, it's still
around), I would like to offer my opinion that, as convenient as
monitored variables are in the short term, they can have very
undesirable side effects in the long term.  In fact, on my project,
which is involved with the largest Simscript model in existence, we
have of late begun to take a more object-oriented approach.  Rather
than assign a variable and let that cause a side-effect, we would
rather define a behavior, one of whose steps would be the storing of a
value in a variable or an attribute of an entity (a field of a
record-like object/structure).  As long as all of the developers
follow the conventions for such abstract data types, we have far more
predictable model behavior.

Helmut, it looks like the answer is no, but that might be for the
best.

Regards,
Jay




More information about the Python-list mailing list