so in case you're wondering why JS VMs have been at the forefront of the development of new float->string algorithms for the past decade.... yeah.
Conversation
They added Map as a proper key-value data structure so it's a good idea to ban using objects as map data structure now, just like banning any usage of `var` (using only let/const) with "use strict" to prevent implicit usage of that nonsense broken form of scoping with hoisting.
1
Except it's not a proper key-value data structure, arrays and objects used as keys in one do the lookup via the use of the `==` operator. So it might work, until it doesn't because you got a key in from a different path and then nothing works.
1
I don't think it's reasonable to blame Map for objects implementing equality as reference equality. It would be worse if it deviated from the standard definition of equality in the language. Arrays and objects are what need to be fixed, not Map using `===` (it doesn't use `==`).
1
1
[1, 2, 3] === [1, 2, 3] being false is the real problem. I think they'll eventually end up having old and new style objects exactly like what happened in Python2 since there are so many problems with how operators handle objects and how objects work.
1
1
I think it's entirely reasonable, they just shouldn't have been added in the first place. Just ignoring the old problems and building more on top of the same sandy base is dangerous and probably negligent.
1
They don't need to change Map to fix these problems though. It would be able to work with a new form of arrays and/or operator overloading. Reference equality also wouldn't be the end of the world if it was only a default which could be overridden, like Python3 objects.
1
Map doesn't rule out introducing a way for objects to define equality and a hash function in the future like other languages. The initial implementation didn't need to be tied to other major new features. I think they're doing a great job with the terrible base they were given.
2
Replying to
But if arrays and objects are effectively off the cards as keys, then it's basically a very, very marginally improved object dictionary. It's yet another thing added that screws over beginners and leaves a nice fat landmine in the codebase for skilled developers.
1
Replying to
I don't see that. It improves a lot of subtle things that go wrong when using objects as dictionaries. By the way, objects in Python 3 have reference equality as the default implementation too. The difference is that you can override the implementation of equality and hashing.
It would have been nice if they implemented more in ES6, but having Map and Set is still a nice improvement without custom equality and hashing implementations. Arrays contain arbitrary objects so that still depends on how equality is defined for arbitrary objects too.
Replying to
Not really a compelling argument for me coming from (of recent) as Haskell/Scala/Purescript background.
1
Replying to
Dynamically typed languages don't have the same design options available to them for this as statically typed languages. It's messier and I don't think throwing exceptions when the types don't match on either side and don't explicitly provide an equality method is really better.
1
Show replies



