On Nov 7, 2017, at 01:51, Petr Viktorin <encu...@gmail.com> wrote:
> 
> When I explained this in 3.5, dicts rearranging themselves seemed quite weird 
> to the newcomers.
> This year, I'm not looking forward to saying that dicts behave "intuitively", 
> but you shouldn't rely on that, because they're theoretically allowed to 
> rearrange themselves.
> The concept of "implementation detail" and language spec vs. multiple 
> interpreter implementations isn't easy to explain to someone in a "basic 
> coding literacy" course.

Perhaps, but IME, it’s not hard to teach someone that in a code review.  Today, 
if I see someone submit a change that includes an implicit assumption about 
ordering, I’ll call that out.  I can say “you can’t rely on dicts being 
ordered, so if that’s what you want, use an OrderedDict or sort your test 
data”.  That’s usually a localized observation, meaning, I can look at the diff 
and see that they are assuming dict iteration ordering.

What happens when built-in dict’s implementation behavior becomes a language 
guarantee?  Now the review is much more difficult because I probably won’t be 
able to tell just from a diff whether the ordering guarantees are preserved.  
Do they delete a key somewhere?  Who knows?   I’m not even sure that would be 
statically determinable since I’d have to trace the use of that dictionary at 
run time to see if some “del d[key]” is deleting the key in the dict under 
review or not.  I can probably only tell that at run time.

So how to I accurately review that code?  Is the order presumption valid or 
invalid?

Cheers,
-Barry

Attachment: signature.asc
Description: Message signed with OpenPGP

_______________________________________________
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