Delegation in Python

Chris Angelico rosuav at gmail.com
Sat Jan 24 19:07:53 EST 2015


On Sun, Jan 25, 2015 at 10:59 AM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>> You can always "monkey-path" the Fraction class on the fly to add a new
>> method to it.  I think most would consider this a bad idea, but it does
>> work.
>
> As regards this being a bad idea I'd suggest the latest score is
> Practicality 1 Purity 0 :)

Indeed. But there's a huge difference between simple and complex
projects. I had a bit of a nightmare trying to figure out what was
going on with a project's logging... it looked like the Python logging
module, but there was another argument being processed, courtesy of
some monkey-patching. Try to keep these changes to small projects,
where it's easier to keep everything in your head; or for a temporary
bit of debugging, where you just want to do this temporarily and then
undo it again when you find the bug. Otherwise, it gets confusing for
the subsequent reader.

ChrisA



More information about the Python-list mailing list