[Baypiggies] Frequently Argued Objections
kelly at nttmcl.com
Mon Jun 23 08:53:08 CEST 2008
Warren Stringer wrote:
> On Jun 21, 2008, at 7:13 PM, Shannon -jj Behrens wrote:
>> On Sat, Jun 21, 2008 at 11:18 AM, Warren Stringer <warren at muse.com>
>>> Yee HAW! Here, have some beef jerky while I explain why us cowboy
>>> programmers are annoyed: Self has to be explicitly used yet is
>>> passed as a parameter. Second, when counting keywords in the standard
>>> library, "self" is the most common keyword, beating the 2nd most common
>>> keyword by almost a factor of two. I mentioned this to JJ, who says
>>> that he
>>> uses self and non-self in the same code base. I would love to see an
>>> where this is useful, where the NRO wouldn't suffice. As a mere
>>> Pythonista, all I see "self" doing is obfuscating the wide open white
>>> that I have grown to love.
>> Are you sure it was me? Are you referring to calling self by another
>> name? I might have said it's possible, but I don't remember ever
>> doing it.
> *Is* there a reason to NOT use self? If not, then self is redundant. If
> the reason to use self is to bypass name resolution order, then I would
> suggest making the less common case explicit and the more common one
I admit, I have had to call self by another name on a couple of
occasions. Specifically, I had a factory method in one class that
returned instances of a dynamically-created class. The returned objects
had methods that referenced both their own instance's attributes and
attributes of the factory method's parent object (via closure). Since
there were two objects involved, I used self to refer to the
factory-generated object itself, and had the factory method use a
different name for its own object reference argument so the generated
object could still access both.
Possible with implicit self? Nope.
* In case anyone is curious, the dynamically-created classes where
ctypes.Structure subclasses whose fields depended on the OS (hence
the need for a factory). The structures contained pointers into a
data structure represented by the factory method's class (also a
ctypes.Structure subclass) so references needed to be held to the
parent object to prevent it being GC'ed prematurely.
More information about the Baypiggies