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

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Tue Apr 8 07:59:41 EDT 2008


On 8 avr, 11:39, méchoui <laurent.pl... at gmail.com> wrote:
> 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:

I've ten years of experience, definitively don't care about looking
"cool" or "l33t", and sorry, but I won't buy your purely ideological
arguments. This reminds me of the lead engineer in one of my first job
forbidding using OO because he didn't get it, or some Java guy trying
to convince me that a language with dynamic typing and no access
restriction could not be used for "production code".

> >                                 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.

Then we should forbid inheritence - you don't see the inherited
functions when reading the code of the class. And we should forbid
monkey-patching, metaclasses and quite a lot of other things as well.
And also, we should go back to static typing - with dynamic typing,
you don't know by reading the signature of a function what kind of
arguments it expects.

C'mon, be serious guys. As everything else, the problem is not with
the feature, but with knowing how to properly use it and how to not
abuse it. If you don't trust the programmer, then don't use a dynamic
language. You know where to find Java and Ada...



More information about the Python-list mailing list