On Tue Dec 16 2014 at 2:05:28 PM Mark Roberts <wiz...@gmail.com> wrote:

> Perhaps you are correct, and I will attempt to remain more constructive on
> the topic (despite it being an *incredibly* frustrating experience).
> However, my point remains: this is a patently false thing that is being
> parroted throughout the Python community, and it's outright insulting to be
> told my complaints about writing 2/3 compatible code are invalid on the
> basis of "premature optimization".
>

See, you're still using a very negative tone even after saying you would
try to scale it back. What Antoine said is not patently false and all he
said was that relying on iter*() methods on dicts is typically a premature
optimization for Python 2 code which is totally reasonable for him to say
and was done so in a calm tone. He didn't say "you are prematurely
optimizing and you need to stop telling the community that because you're
wasting everyone's time in caring about performance!" which how I would
expect you to state it if you were make the same claim based on how you
have been reacting.

For most use cases, you simply don't need a memory-efficient iterator. If
you have a large dict where memory issues from constructing a list comes
into play, then yes you should use iterkeys(), but otherwise the overhead
of temporarily constructing a list to hold all the keys is cheap since it's
just a list of pointers at the C level.

As for the changing of the default in Python 3, that's because we decided
to make iterators the default everywhere. And that was mostly for
consistency, not performance reasons. It was also for flexibility as you
can go from an iterator to a list by just wrapping the iterator in list(),
but you can't go the other way around. At no time did anyone go "we really
need to change the default iterator for dicts to a memory-saving iterator
because people are wasting memory and having issues with memory pressure
all the time"; it was always about consistency and using the best idiom
that had developed over the years.

So Antoine's point is entirely reasonable and valid and right.

-Brett


>
> -Mark
>
> On Tue, Dec 16, 2014 at 10:57 AM, Brett Cannon <br...@python.org> wrote:
>>
>> Mark, your tone is no longer constructive and is hurting your case in
>> arguing for anything. Please take it down a notch.
>>
>> On Tue Dec 16 2014 at 1:48:59 PM Mark Roberts <wiz...@gmail.com> wrote:
>>
>>> On Tue, Dec 16, 2014 at 2:45 AM, Antoine Pitrou <solip...@pitrou.net>
>>> wrote:
>>>>
>>>> Iterating accross a dictionary doesn't need compatibility shims. It's
>>>> dead simple in all Python versions:
>>>>
>>>> $ python2
>>>> Python 2.7.8 (default, Oct 20 2014, 15:05:19)
>>>> [GCC 4.9.1] on linux2
>>>> Type "help", "copyright", "credits" or "license" for more information.
>>>> >>> d = {'a': 1}
>>>> >>> for k in d: print(k)
>>>> ...
>>>> a
>>>>
>>>> $ python3
>>>> Python 3.4.2 (default, Oct  8 2014, 13:08:17)
>>>> [GCC 4.9.1] on linux
>>>> Type "help", "copyright", "credits" or "license" for more information.
>>>> >>> d = {'a': 1}
>>>> >>> for k in d: print(k)
>>>> ...
>>>> a
>>>>
>>>> Besides, using iteritems() and friends is generally a premature
>>>> optimization, unless you know you'll have very large containers.
>>>> Creating a list is cheap.
>>>>
>>>
>>> It seems to me that every time I hear this, the author is basically
>>> admitting that Python is a toy language not meant for "serious computing"
>>> (where serious is defined in extremely modest terms). The advice is also
>>> very contradictory to literally every talk on performant Python that I've
>>> seen at PyCon or PyData or ... well, anywhere. And really, doesn't it
>>> strike you as incredibly presumptuous to call the *DEFAULT BEHAVIOR* of
>>> Python 3 a "premature optimization"? Isn't the whole reason that the
>>> default behavior switch was made is because creating lists willy nilly all
>>> over the place really *ISN'T* cheap? This isn't the first time someone has
>>> tried to run this line past me, but it's the first time I've been fed up
>>> enough with the topic to call it complete BS on the spot. Please help me
>>> stop the community at large from saying this, because it really isn't true
>>> at all.
>>>
>>> -Mark
>>> _______________________________________________
>>> Python-Dev mailing list
>>> Python-Dev@python.org
>>> https://mail.python.org/mailman/listinfo/python-dev
>>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
>>> brett%40python.org
>>>
>>
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to