A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2003-May/035583.html below:

[Python-Dev] Re: __slots__ and default values

[Python-Dev] Re: __slots__ and default valuesMichael Chermside mcherm@mcherm.com
Tue, 13 May 2003 08:25:18 -0700
Raymond Hettinger wrote:
> class Pane(object):
>     __slots__ = ('background', 'foreground', 'size', 'content')
>     background = 'black'
>     foreground = 'white'
>     size = (80, 25)
...which doesn't work since the class variable overwrites the
__slots__ descriptor.


Aahz replies:
> Why not do the initializing in __init__?

I presume that Raymond's concern was not that there wouldn't be
a way to do initialization, but that this would become a new c.l.p
FAQ and point of confusion for newbies. Unfortunately, I fear
that it will. Already I am seeing that people are "discovering"
class variables as a sort of "initialized instance variable"
instead of using __init__ as they "ought" to. Of course, it's NOT
an initialized instance variable, but newbies stumble across it
and seem to prefer it to using __init__.

Combine this with the fact that newbies from staticly typed 
languages tend to think of __slots__ as "practically mandatory" 
(because it prevents the use of instance variables not pre-declared,
which they erroniously think is a good thing) rather than the 
special purpose performance hack that it REALLY is, and you have
a recipe for trouble.

I'm not quite sure how to present things so as to steer them
right, but there's definitely a potential pitfall here.

-- Michael Chermside




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4