3 ms·
Is the ordering there at least fixed, or can it vary from run to run even on the same data, or between implementations or versions of the same implementation?
by pfdietz 7y ago
Is the ordering there at least fixed, or can it vary from run to run even on the same data, or between implementations or versions of the same implementation?
EDIT: to clarify, I was asking about JavaScript there.
- deleted 7y ago[deleted]
- nobleach 7y agoIt is deterministic, but it's an odd rule-set. For example: `var o = { 3: 'foo', 1: 'bar', b: 'baz', a: 'quux' }` Will yield: `{1: "bar", 3: "foo", b: "baz", a: "quux"}`. Numeric keys get sorted. String keys are insertion-order. If key order is a priority, a Map should be used instead. Often when JavaScript's objects are used and a particular sort order is required, an accompanying (sorted) array is used.
- deleted 7y ago[deleted]
- blattimwind 7y agoIf the ordering is determined by a hash function and it's always the same it is likely a defect in the implementation, because keys can be easily chosen to cause massive performance degredation; essentially a DoS attack. That's why many dynamic languages these days use things like siphash with a random key.
- pfdietz 7y agoI'll argue that having the order depend on the hash function, rather than insertion order, is the problem. It's bad to have unnecessary nondeterminism in software. It makes testing and reproducing bugs unnecessarily difficult.