logoalt Hacker News

frizlabyesterday at 7:18 PM2 repliesview on HN

Interestingly I think things that should not be deterministic should actually forced not to be.

Swift for instance will explicitly make iterating on a dictionary not deterministic (by randomizing the iteration), in order to catch weird bugs early if a client relies (knowingly or not) on the specific order the elements of the dictionary are ordered.


Replies

lilyballyesterday at 7:47 PM

This claim sounds vaguely familiar to me (though the documentation on Dictionary does not state any reason for why the iteration order is unpredictable), though the more common reason for languages to have unstable hash table iteration orders is as a consequence of protection against hash flooding, malicious input causing all keys to hash to the same bucket (because iteration order is dependent on bucket order).

show 1 reply
saidinesh5yesterday at 8:14 PM

One more reason for randomizing hash table iteration was to prevent Denial of service attacks:

https://lukasmartinelli.ch/web/2014/11/17/php-dos-attack-rev...