Title of the article is "How…", not "Why…", and "why" is not discussed. (My understanding is that the "why" is "because the implementation acted that way without an official guarantee, and folks depended on the implementation detail, so it became guaranteed.)
DemocracyFTW2•3mo ago
I don't think this is the "why". What you're depicting is what happened in JavaScript. Dictionary keys in Python always had that (to me) annoying property that they preserved insertion order until they don't. I'd frankly much prefer if they'd always be iterated in random order each time they're traversed.
not_kurt_godel•3mo ago
I'd love to see the results of mandating a random order dict impl at an actual company/org (but hate to be forced to participate). Hopefully you hired developers who really like to write sorting algos.
yxhuvud•3mo ago
Well, that is how hash tables in go works, so you'd not have to look that far.
not_kurt_godel•3mo ago
Great. Maybe GP will go a step farther and also mandate arrays that return elements in random order too. Relying on insertion order for any reason is for weaklings.
tasty_freeze•3mo ago
Perl since 5.8.something has had the option of perturbing the hash function, so it is different from run to run. You can also set the set to a given value in order to lock in the sequence.
In any case, it is not ordered. If you want that, you have to explicitly sort the keys of the hash.
nielsbot•3mo ago
Swift (heavily used by Apple) has randomly
ordered dictionaries for
security:
> In particular, random seeding enables better protection against (accidental or deliberate) hash-flooding attacks
Swift isn’t popular because its Dictionary type uses randomly ordered keys?
cyanydeez•3mo ago
Probably the inference is YAGNI
.
not_kurt_godel•3mo ago
It certainly could be a reason among many. Just look at the thread GP shared, containing multiple years' worth of users voicing frustration at the introduction of this behavior.
I think the "how/why" thing is just the automatic title de-clickbait-ifer going a little haywire?
snthpy•3mo ago
Thanks, How makes much more sense. The post title is dumb.
Why is Hackernews news for hackers?
bradchoate•3mo ago
The URL for the post includes "why" (en-why-is-python-ordereddict-ordered), so I suppose the title of the article was updated after the HN post was created. The site's native language is Chinese and I'm guessing the post was translated via automation. In fact, if you run the article through an automated translation service (Google Translate), it reproduces the "Why" title.
snthpy•3mo ago
Thanks, makes sense.
more_corn•3mo ago
^ came here to say exactly this
DemocracyFTW2•3mo ago
Wrong title, article has "How Does Python’s OrderedDict Maintain Order?"
addaon•3mo ago
DemocracyFTW2•3mo ago
not_kurt_godel•3mo ago
yxhuvud•3mo ago
not_kurt_godel•3mo ago
tasty_freeze•3mo ago
In any case, it is not ordered. If you want that, you have to explicitly sort the keys of the hash.
nielsbot•3mo ago
> In particular, random seeding enables better protection against (accidental or deliberate) hash-flooding attacks
https://forums.swift.org/t/psa-the-stdlib-now-uses-randomly-...
not_kurt_godel•3mo ago
nielsbot•3mo ago
cyanydeez•3mo ago
not_kurt_godel•3mo ago
recursivecaveat•3mo ago
I think the "how/why" thing is just the automatic title de-clickbait-ifer going a little haywire?
snthpy•3mo ago
Why is Hackernews news for hackers?
bradchoate•3mo ago
snthpy•3mo ago
more_corn•3mo ago