On Fri, May 20, 2005 at 05:10:30PM -0400, Dan Pozmanter wrote:
> What is morally wrong with modifying live objects in a dynamic language
> to achieve desired functionality?
> The idea is "I want to modify the zope core in a way that survives
> version to version, yet does not
> impose a specific use case on all zope users".

I don't want to overgeneralize, but the "moral" issue I have with
monkey-patching is illustrated by an anecdote.

Once I was attempting to debug a problem with a core Zope product.
It was behaving in a baffling fashion that contradicted what the
source code was telling me. It was only during a tedious pdb session
that I discovered that a third-party product had monkey-patched
the method in question. (This turned out not to be the cause of the
problem we were having - but the mystery wasted an hour of my time 
when I was facing a deadline.)

The lesson is: python code may be eminently readable, and on this list
we are fond of telling users to "use the source" - but a monkeypatch in
some obscure corner of an add-on package can turn the source code into a
big fat lie.

That's evil :-)

Of course, sometimes it is a necessary (or at least expedient)
evil... sometimes you need a hook where there just isn't one
and you have no choice but to bash your way in there like a
500-pound gorilla.  So, I monkeypatch, and I feel guilty :-)



Paul Winkler
Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to