Is there an official way to add methods to an instance?

méchoui laurent.ploix at gmail.com
Tue Apr 8 05:39:04 EDT 2008


On Apr 4, 5:25 pm, John Nagle <na... at animats.com> wrote:
> Bruno Desthuilliers wrote:
> > Paul Rubin a écrit :
> >> Brian Vanderburg II <BrianVanderbu... at aim.com> writes:
> >>> I've checked out some ways to get this to work.  I want to be able to
> >>> add a new function to an instance of an object.
>
> >> Ugh.  Avoid that if you can.
>
> > Why so ? OO is about objects, not classes, and adding methods on a
> > per-object basis is perfectly legitimate.
>
>     It's what professional programmers call a "l33t feature",
> one not suitable for production code.  Typically such features
> are used by programmers with about two years experience,
> trying too hard to prove that they're cool.
>
>                                 John Nagle

Yes, and the reason is quite obvious: if you read the code of the
class, you can't see the function. That makes it much more difficult
to understand and to debug.



More information about the Python-list mailing list