[Python-Dev] Oberver Pattern

holger krekel pyth@devel.trillke.net
Wed, 15 May 2002 11:34:45 +0200


Raymond Hettinger wrote:
> From: "Greg Ewing" <greg@cosc.canterbury.ac.nz>
> > Having thought it through a bit more, you're probably
> > right. I just thought it might appeal to Magnus, since
> > he seems to be fond of lots of layers of magic, without
> > much if any regard for performance...
> 
> FWIW, the early results from my test implementation is
> that there is no measurable performance impact if
> an observer function has not been attached or if
> the observer function is a short C call (perhaps
> setting a flag or logging the object id).  The only way to 
> slow it down enough for the timer to notice seems to be 
> attaching a pure python function to be notified.
>
> IOW, the observer pattern doesn't slow you down until
> you need it.  And, if you need it, then you're probably
> doing it to save much more time being spent on repeated
> checks to see if a change has taken place and to save
> programmer effort by de-coupling the objects.

Is the functionality complete enough to justify such statements?
Not everything is setattr(self, ...) but you have e.g.

    somelist.append(...)

where 'somelist' might be bound to an object which in turn is also bound
as an attribute of an observed object. 

In my understanding objects don't know which names bind it, right?
Additionally this is a recursive problem:

  A has a B-instance has a C instance has a D instance attribute

if you observe A and change D, what happens?

without this functionality speed/space measurements are obsolete IMO.

    holger