On Wed, 30 Nov 2022 at 10:48, Steven D'Aprano <st...@pearwood.info> wrote:
> Let's consider a thought-experiment: suppose we agree to your proposal
> to make hash(None) return a constant, but at the same time modify the
> set iteration algorithm so that it starts from a different position each
> time you iterate, making set iteration order even more unpredictable and
> deterministically chaotic than it is now.

Let's consider an equally-likely thought experiment: suppose that
every call to set.__iter__() causes a short busy-wait, spinning the
CPU for a little while for absolutely no purpose. There's nothing in
the docs that mandates performance, so it would be perfectly
reasonable for a future version of Python to do this, right? But it's
not something that I would consider *likely*.

And, in fact, modifying the iteration algorithm to be completely
unpredictable would have the same cost: an RNG lookup for no value
whatsoever.

It's notable that set() is about the only data type where this is
possible. You can't randomize dict iteration order (couldn't do that
even before it was locked in, because iterating over keys and values
was always required to return them in the same order), and a lot of
arbitrary-order collections are built on top of dictionaries. So your
thought experiment would be special-casing sets and making them
unnecessarily difficult to work with, just so you can point to that
arbitrariness and say "hah! GOTCHA! You silly fools shouldn't have
been depending on iteration order!!".

> Personally, and I don't expect that this will be a popular opinion, I
> wish that data structures that don't guarantee their iteration order
> would actively mix up their iteration order so that people wouldn't be
> tempted to rely on whatever accidental order they happen to get.

Which data structures are those? Please enumerate.

> Sure, it would cost a little bit of code to implement, but think of the
> savings in unproductive arguments and discussions like this one :-(

So basically, it's a bit of useless code, a bit of useless CPU usage,
all just so you can win an argument. Makes sense.

ChrisA
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/E4EVMJRFTQIKZIQMEHEB2SF7FORMZUO5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to