__slots__ and multiple inheritance

Carl Banks imbosol at vt.edu
Sun Dec 15 13:23:37 EST 2002


Bengt Richter wrote:
> On Sat, 14 Dec 2002 20:19:40 -0500, Carl Banks <imbosol at vt.edu> wrote:
> 
>>Bengt Richter wrote:
>>> ISTM __xxx__ primarily serves as an object definition metalanguage (1).
>>> I.e., we use it to compose objects with standard behaviours and attributes
>>> used implicitly in higher level constructs.  Perhaps moving towards using
>>> __xxx__ purely for that primary purpose would be a good thing?
>>> 
>>> 1. standard primitive object attributes
>>> 2. compiler hints/directives
>>>    2.1 allocation-related
>>>    2.2 metaclass linkage
>>> 3. import/loader hints/directives
>>> 4. ?
>>
>>Personally, I don't have any problem with __xxx__ meaning simply "this
>>symbol has extra or different meaning given to it by the language."
> Me neither (1. above), but I was talking about whether some __xxx__ codes are
> really impostors and not part of the programming language *itself* at all,
> any more than -OO is part of the language *per se*.

Can you think of any examples?  Off hand, I can't.


>>> I.e. __slots__ seems effectively an optimization hint (actually
>>> directive, I guess).  Or is the restriction above a design intent
>>> rather than a necessary side effect?
>>
>>No, it's definitely a necessary side effect.  If they could have done
>>it without the MI restriction, they would have.  And it's definitely
>>not an optimization.  Its purpose is to help avoid misspelling bugs.
> 
> Excerpt from http://www.python.org/2.2/descrintro.html:
> 
[snip excerpt]
> 
> which sounds to me like space optimization is at least a desired side effect.

Well, I was thinking it was definitely not a speed optimization.  Call
me a speed guy.  Certainly it does save a lot of space.  You are
correct.


>>Personally, I never use slots, because I've never found misspelling
>>bugs to be much of a problem.
>>
> If you don't use a tool to help check set-but-never-used in a large program,
> the probability of a silent binding to a misspelled name is nonzero ;-)
> And if it happened on exit from a loop where you were binding the last value
> of a converging approximation algorithm, the chances of your noticing that
> it didn't "take" is low, unless you are "anal" about testing ;-)

I understand your point.  Call me anal about checking spelling as I
type :-).




-- 
CARL BANKS



More information about the Python-list mailing list