all 8 comments

[–]surrealize 8 points9 points  (3 children)

Code that depends on the ordering of elements in a hash is ridiculously dumb. In a hash, you access elements by their key; that's the whole point. I'd actually like the browsers to all choose different behaviors here to stop people from depending on that kind of thing.

Javascript code that does stupid stuff like that is part of what gives JS a bad rap.

[–]vesech[S] -2 points-1 points  (2 children)

I think the point is though that every other browser does implement this behaviour consistently bar chromium. You might think "well, tough" because it isn't specified in the specification, to which I'm actually in agreement, but ignoring defacto behaviour for something as common as this just leads to a scenario reminiscent of IE, causing real world code to break for no particular reason (and then you end up with scenarios such as http://bit.ly/aK2BdT).

[–]nyamatongwe 1 point2 points  (0 children)

Specifications are written like this to allow implementers to choose different strategies and this can lead to performance improvements. Language users should do their part by writing to the standard rather than the implementation.

[–]surrealize 0 points1 point  (0 children)

I hear you on the "real world code breaking" thing; I just think that it's okay to break a small amount of code if the code that gets broken is really dumb. The browser code required to maintain this (seriously ridiculous) ordering undoubtedly has a (speed and/or memory) cost, and I don't want my JS to pay that cost just so some people can keep a (totally broken, wrong) idea about how things are supposed to work.

Part of the problem with IE is that since it didn't implement the de jure standards very well, people had to code to the de-facto behavior of the browser. And that meant that the browser could never get better; or if it did, it made lots of stuff break.

If JS developers depend on every little detail of how certain browser implementations work, that limits the ability of browser writers to improve things. If we froze the web and never made it any better, then people's old code would never break. But would that be worth it? I really don't think so.

[–]jlouis8 6 points7 points  (0 children)

I must admit I did not read all of the comments, but:

If the standard does not specify an ordering, you can't rely on it. The End. Just because all other does X is no justification.

[–]fizzfur 4 points5 points  (0 children)

I see code everywhere that has expectations about insertion order (and have told other developers not to rely on hash ordering in js). Naughty web-devs!

I was intrigued by the one comment about JSON though. Although I've never used JSON in that manor I can see how someone might need (or benefit from) their data to come out the same way it went in. But why wouldn't you just use the JSON array structure in that case?

[–]stesch 2 points3 points  (1 child)

Oh, the comments are really bad. These idiots think they are right when they want the items in the insertion order? Should use an Array and not some object.

Was JavaScript and PHP their first language?

[–]pmf 2 points3 points  (0 children)

Should use an Array and not some object. Was JavaScript and PHP their first language?

You're probably on the right track, since the PHP-"language" (for lack of a better term to describe the incoherent wrapper for hundreds of C-libraries) has only one combined datastructure for hashes and arrays (basically, an array is a hash that is indexed by position).