3 ms·
I would otherwise agree that JS's standard library is too small, but I don't think your example showcases it. Which languages offer this in their standard libra
by Sacho 9y ago
I would otherwise agree that JS's standard library is too small, but I don't think your example showcases it. Which languages offer this in their standard library? It's not in any of the languages I have used: C, C++, C#, Java, PHP, Python..
A better example would be the extremely poor Date object, which has only a couple format functions and can't even be created from a specified format. There's also a bunch of holes when manipulating data, filled by libraries like lodash(although the standard lib has improved significantly in this regard).
- panic 9y agoWhich languages offer this in their standard library? It's not in any of the languages I have used: C, C++, C#, Java, PHP, Python.. Off the top of my head, Haskell has "deriving Eq", and Scheme has "equal?". I'm pretty sure Python uses deep equality for tuples as well. Anyway, it's just one example of something I wanted to do in JS recently and ended up disappointed in the quality of the code I saw to do it.
- sametmax 9y agoPython does: >>> {"foo": [1, 2, set([True])]} == {"foo": [1, 2, set([False])]} False >>> {"foo": [1, 2, set([True])]} == {"foo": [int('1'), 2, set([bool(1)])]} True
- Sacho 9y agoYou're right, I forgot about those and overstated my case.
- always_good 9y agoI don't blame you. I think the only reason I ever do deep comparison is in unit tests, and every test/assertion library has a `deepEquals` assertion, so it's not something I regularly miss. There are better examples of deficiencies in Javascript's standard library, especially when targeting browsers, but Javascript has made massive strides lately like its native Set and Map datastructures. For example, Set doesn't come with the classic methods `.intersection()` / `.difference()` / `.union()` / etc. but it's just not a defining moment of my overall experience with Javascript. We're long past the days where you had to bring your own `Array#map`, but I don't know if all of these commenters are.
- robhu 9y agoRuby too: irb(main):002:0> {'foo' => [1, 2, [true].to_set]} == {'foo' => [1, 2, [false].to_set]} => false irb(main):003:0> {'foo' => [1, 2, [true].to_set]} == {'foo' => ['1'.to_i, 2, [true].to_set]} => true
- deleted 9y ago[deleted]
- divs1210 9y agoIn Clojure = is the deep equality op. (= 1 1) is true.
- sseagull 9y agoC++ has this kind of equality for STL containers. Create nested maps, vectors, lists, sets, strings, etc, and you can just compare them with "==". It will do a deep compare.