Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-15 Thread Aahz
In article [EMAIL PROTECTED],
Steven Bethard  [EMAIL PROTECTED] wrote:
Aahz wrote:
 In article [EMAIL PROTECTED],
 Steven Bethard  [EMAIL PROTECTED] wrote:

 You can use __slots__  [...]
 
 Aaaugh!  Don't use __slots__!
 
 Seriously, __slots__ are for wizards writing applications with huuuge
 numbers of object instances (like, millions of instances).

You clipped me saying that __slots__ are for performance tweaks:

 You can use __slots__ to make objects consume less memory and have
 slightly better attribute-access performance. Classes for objects
 that need such performance tweaks should start like...

I fully agree that __slots__ are for applications with huge numbers of 
instances. But if you have that situation, you really do want to be 
using __slots__.

Well, then, just make sure to put big honking warnings up whenever you
mention __slots__.  ;-)
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven D'Aprano
On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote:

 In article [EMAIL PROTECTED], Steven
 Bethard  [EMAIL PROTECTED] wrote:

You can use __slots__  [...]
 
 Aaaugh!  Don't use __slots__!
 
 Seriously, __slots__ are for wizards writing applications with huuuge
 numbers of object instances (like, millions of instances).  For an
 extended thread about this, see
 
 http://groups.google.com/group/comp.lang.python/browse_thread/
thread/8775c70565fb4a65/0e25f368e23ab058

Well, I've read the thread, and I've read the thread it links to, and for 
the life of me I'm still no clearer as to why __slots__ shouldn't be used 
except that:

1 Aahz and Guido say __slots__ are teh suxxor;

2 rumour (?) has it that __slots__ won't make it into Python 3.0;

3 inheritance from classes using __slots__ doesn't inherit the slot-
nature of the superclass.


Point 1 is never to be lightly dismissed, but on the other hand Guido 
doesn't like reduce(), and I'm allergic to Cos I Said So arguments.

History is full of things which were invented for one purpose being used 
for something else. So, that being the case, suppose I accept that using 
__slots__ is not the best way of solving the problem, and that people of 
the skill and experience of Guido and Aahz will roll their eyes and 
snicker at me.

But is there actually anything *harmful* that can happen if I use 
__slots__?



-- 
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Diez B. Roggisch
Steven D'Aprano wrote:

 On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote:
 
 In article [EMAIL PROTECTED], Steven
 Bethard  [EMAIL PROTECTED] wrote:

You can use __slots__  [...]
 
 Aaaugh!  Don't use __slots__!
 
 Seriously, __slots__ are for wizards writing applications with huuuge
 numbers of object instances (like, millions of instances).  For an
 extended thread about this, see
 
 http://groups.google.com/group/comp.lang.python/browse_thread/
 thread/8775c70565fb4a65/0e25f368e23ab058
 
 Well, I've read the thread, and I've read the thread it links to, and for
 the life of me I'm still no clearer as to why __slots__ shouldn't be used
 except that:
 
 1 Aahz and Guido say __slots__ are teh suxxor;
 
 2 rumour (?) has it that __slots__ won't make it into Python 3.0;
 
 3 inheritance from classes using __slots__ doesn't inherit the slot-
 nature of the superclass.
 
 
 Point 1 is never to be lightly dismissed, but on the other hand Guido
 doesn't like reduce(), and I'm allergic to Cos I Said So arguments.
 
 History is full of things which were invented for one purpose being used
 for something else. So, that being the case, suppose I accept that using
 __slots__ is not the best way of solving the problem, and that people of
 the skill and experience of Guido and Aahz will roll their eyes and
 snicker at me.
 
 But is there actually anything *harmful* that can happen if I use
 __slots__?

Point 3 clearly is harmful. As is the fact that __slots__ gives you troubles
if you e.g. pass objects to code that tries to set arbitrary attributes on
an object. While this might be frowned upon, it can be useful in situations
where you e.g. link GUI-code/objects with data-objects: instead of creating
cumbersome, explicit mappings (as you have to in C/C++/Java) or wrappers,
just set a well-named property.

The question is: what does a slot buy you for this kind of problem? And
while arguing with then I can't set an attribute I didn't want to be set
is certainly possible, it ultimately leads to the darn
static-vs-dynamic-discussion. Which we might spare us this time.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven D'Aprano
On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote:

 Well, I've read the thread, and I've read the thread it links to, and
 for the life of me I'm still no clearer as to why __slots__ shouldn't
 be used except that:
 
 1 Aahz and Guido say __slots__ are teh suxxor;
 
 2 rumour (?) has it that __slots__ won't make it into Python 3.0;
 
 3 inheritance from classes using __slots__ doesn't inherit the slot-
 nature of the superclass.
 
 
 Point 1 is never to be lightly dismissed, but on the other hand Guido
 doesn't like reduce(), and I'm allergic to Cos I Said So arguments.
 
 History is full of things which were invented for one purpose being
 used for something else. So, that being the case, suppose I accept that
 using __slots__ is not the best way of solving the problem, and that
 people of the skill and experience of Guido and Aahz will roll their
 eyes and snicker at me.
 
 But is there actually anything *harmful* that can happen if I use
 __slots__?
 
 Point 3 clearly is harmful. 

No, it is DIFFERENT, not harmful. At worst, it's a gotcha -- a really 
well-documented gotcha.


 As is the fact that __slots__ gives you
 troubles if you e.g. pass objects to code that tries to set arbitrary
 attributes on an object.

You mean like this?

 x = 1
 x.label = foo
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'int' object has no attribute 'label'

I guess that means ints and floats and strings and tuples and lists are 
all harmful too, yes?



 The question is: what does a slot buy you for this kind of problem?

Simplicity and explicitness.



-- 
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Diez B. Roggisch
Steven D'Aprano wrote:

 On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote:
 
 Well, I've read the thread, and I've read the thread it links to, and
 for the life of me I'm still no clearer as to why __slots__ shouldn't
 be used except that:
 
 1 Aahz and Guido say __slots__ are teh suxxor;
 
 2 rumour (?) has it that __slots__ won't make it into Python 3.0;
 
 3 inheritance from classes using __slots__ doesn't inherit the slot-
 nature of the superclass.
 
 
 Point 1 is never to be lightly dismissed, but on the other hand Guido
 doesn't like reduce(), and I'm allergic to Cos I Said So arguments.
 
 History is full of things which were invented for one purpose being
 used for something else. So, that being the case, suppose I accept that
 using __slots__ is not the best way of solving the problem, and that
 people of the skill and experience of Guido and Aahz will roll their
 eyes and snicker at me.
 
 But is there actually anything *harmful* that can happen if I use
 __slots__?
 
 Point 3 clearly is harmful.
 
 No, it is DIFFERENT, not harmful. At worst, it's a gotcha -- a really
 well-documented gotcha.

To the casual observer? I doubt it. I wasn't aware of that until a recent
discussion about slots. But then, I've so far _never_ felt the need to  use
them...
 
 
 As is the fact that __slots__ gives you
 troubles if you e.g. pass objects to code that tries to set arbitrary
 attributes on an object.
 
 You mean like this?
 
 x = 1
 x.label = foo
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'int' object has no attribute 'label'
 
 I guess that means ints and floats and strings and tuples and lists are
 all harmful too, yes?

You are very well aware that I was talking about complex objects. And I
didn't say that they are harmful, but that using __slots__ to constrain
object attribute will lead to surprising results here in comparison to
the usual behavior. And with usual I mean
most-of-the-classes-work-that-way. Which might be considered as reason to
_not_ do it. But you are free to limit yourself, be my guest.

 The question is: what does a slot buy you for this kind of problem?
 
 Simplicity and explicitness.

Where is that more simple? Additional notation that will lead to
runtime-errors, the same way misspelled attribute-names do?

And yes, it is more explicit. As are interfaces, and type declarations. 

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven Bethard
Aahz wrote:
 In article [EMAIL PROTECTED],
 Steven Bethard  [EMAIL PROTECTED] wrote:
 You can use __slots__  [...]
 
 Aaaugh!  Don't use __slots__!
 
 Seriously, __slots__ are for wizards writing applications with huuuge
 numbers of object instances (like, millions of instances).

You clipped me saying that __slots__ are for performance tweaks:

 You can use __slots__ to make objects consume less memory and have
 slightly better attribute-access performance. Classes for objects
 that need such performance tweaks should start like...

I fully agree that __slots__ are for applications with huge numbers of 
instances. But if you have that situation, you really do want to be 
using __slots__.

STeVe
-- 
http://mail.python.org/mailman/listinfo/python-list


Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-07 Thread Aahz
In article [EMAIL PROTECTED],
Steven Bethard  [EMAIL PROTECTED] wrote:

You can use __slots__  [...]

Aaaugh!  Don't use __slots__!

Seriously, __slots__ are for wizards writing applications with huuuge
numbers of object instances (like, millions of instances).  For an
extended thread about this, see

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8775c70565fb4a65/0e25f368e23ab058
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-07 Thread Michele Simionato
On Oct 8, 12:27 am, [EMAIL PROTECTED] (Aahz) wrote:

 Aaaugh!  Don't use __slots__!

+1 QOTW  ;)

Michele Simionato

-- 
http://mail.python.org/mailman/listinfo/python-list