Why self?
Louis M. Pecora
pecora at anvil.nrl.navy.mil
Tue Jul 9 15:58:26 EDT 2002
In article <yu99adp0ych2.fsf at europa.research.att.com>, Andrew Koenig
<ark at research.att.com> wrote:
> Louis> def __init__(self):
> Louis> name=None
>
> But that's extra code. I thought the whole point was to get rid of
> extra code, not move it around.
Getting rid of distracting code was my motive. I always try to
initialize object variables. That helps me when I look over an object
and I thought that was good practice. Hence, it adds no code for me.
>
> What about someone who wants to write several classes with methods
> that behave exactly the same way? Doesn't it make sense to write that
> code once, and then install references to it in each of those classes?
I would answer: use inheritance.
> What about code that wants to build up objects with particular
> properties by installing methods dynamically in those objects
> according to the requested specifications?
Oh, I see adding functionality on the fly. Interesting idea. Is that
really undoable with my suggestion? My mind is hitting a wall trying
to see that, sorry.
> Because requiring "self" has some advantages, as well as the disadvantages
> that you and others have mentioned, it's a matter of opinion as to whether
> a solution to the problem would create other problems. For that reason,
> I'm not inclined to go looking for a detailed solution--especially as
> any solution would have to avoid breaking existing code.
^^^^^^^^^^^^^^^^^^^^^^
Yeah, that's true.
Sigh. Looks like I live with self. Now that sounds deeply Jungian
or something.
Thanks for the feedback.
--
Lou Pecora
- My views are my own.
More information about the Python-list
mailing list