4 ms·
I think most of the things I'd want to see first would come in the standard library and in unicode handling. I'd probably argue that most uses of metaclasses a
by mpdehaan2 12y ago
I think most of the things I'd want to see first would come in the standard library and in unicode handling.
I'd probably argue that most uses of metaclasses are a reason to step back and make the code simpler. There are a few cases where they come in very usefully, but at least in open source code, they create a barrier to understanding and increase complexity.
ython starts to get ugly when you start writing code that does "automagical things", and that's somewhat tolerated because it's not a language for building automagical things.
Or, to say it another way, if you have to think about how the interpreter works, your python has jumped off the idiomatic wagon a while ago.
That being said __slots__ as a performance enhancement is crazy useful - and I'd like to see more things in that area.
Though for most people, the thing that would lead to cleaner code would be a more powerful and elegant standard library.
- Dylan16807 12y ago>That being said __slots__ as a performance enhancement is crazy useful Can you be more specific? The article claims that it's not a performance boost at all. Where is it useful?
- ejstronge 12y agoThe article mentions, a bit unclearly, that there are two types of slots: the slots used to implement method dispatch in the interpreter and __slots__ [1-2]. Armin's article is about method dispatch. __slots__ are useful to reduce memory usage when you're instantiating lots (tens of thousands or millions) of Python objects. Since objects defined in Python code support the addition of arbitrary attributes, their members are internally represented as a dictionary which isn't necessary when your tens of thousands of objects have a limited set of attributes. Defining a sequence __slots__ tells the interpreter that your Python class will only need memory for the members defined in that sequence and restricts your ability to arbitrarily add new members (see [1] for details). [1] https://docs.python.org/2/reference/datamodel.html#slots https://docs.python.org/2/reference/datamodel.html#slots [2] http://code.activestate.com/lists/python-list/531365/ http://code.activestate.com/lists/python-list/531365/
- TheLoneWolfling 12y agoNote that in PyPy __slots__ is entirely unnecessary: http://morepypy.blogspot.ca/2010/11/efficiently-implementing-python-objects.html http://morepypy.blogspot.ca/2010/11/efficiently-implementing...
- DasIch 12y ago> That being said __slots__ as a performance enhancement is crazy useful - and I'd like to see more things in that area. Though for most people, the thing that would lead to cleaner code would be a more powerful and elegant standard library. __slots__ as PyPy shows is completely unnecessary.
- masklinn 12y ago1. __slots__ and TFA have nothing to do with one another 2. __slots__ are not actually useful, Pypy does what they do by default and deoptimizes as needed, CPython probably could as well 3. the only thing __slots__ do is lower memory usage (by not allocating a dict per instance) and PEP 412 has already improved that __slots__ is not "crazy useful" by any definition of the expression, it is somewhat useful when you have a huge living number of simple objects.
- PythonicAlpha 12y agoSounds as, that you did not understand, that the author did not mean the __slots__ system, that allows to avoid the __dict__ on objects, but the internal slots-system that is intended to speed up the dispatching of special methods.
- thu 12y agoYou missed his point 1.
- PythonicAlpha 12y agoOk. Then my answer belongs to the first in the sub-tree. What I actually did not understand: What means TFA?
- deleted 12y ago[deleted]
- stewartbutler 12y agoThe Freaking Article.
- PythonicAlpha 12y agoThanks! That helps.
- 12y ago