Problem of Readability of Python

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Oct 8 01:12:29 CEST 2007


On Sun, 07 Oct 2007 13:24:14 -0700, Alex Martelli wrote:

> And yes, you CAN save about 1/3 of those 85 nanoseconds by having
> '__slots__=["zop"]' in your class A(object)... but that's the kind of
> thing one normally does only to tiny parts of one's program that have
> been identified by profiling as dramatic bottlenecks

Seems to me that:

class Record(object):
    __slots__ = ["x", "y", "z"]


has a couple of major advantages over:

class Record(object):
    pass


aside from the micro-optimization that classes using __slots__ are faster 
and smaller than classes with __dict__.

(1) The field names are explicit and self-documenting;
(2) You can't accidentally assign to a mistyped field name without Python 
letting you know immediately.


Maybe it's the old Pascal programmer in me coming out, but I think 
they're big advantages.


-- 
Steven.



More information about the Python-list mailing list