News for hackers. Stuff that matters.
Re:Sick of Ruby, dynamic typing, side effects, and object-or... by Sacho on Tuesday November 07, 2017 @05:22AM (#15642211)
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).

Re:Sick of Ruby, dynamic typing, side effects, and object-or... by sametmax on Tuesday November 07, 2017 @07:41AM (#15642860)
Python 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

Re:Sick of Ruby, dynamic typing, side effects, and object-or... by Sacho on Tuesday November 07, 2017 @08:21AM (#15643095)
You're right, I forgot about those and overstated my case.
Re:Sick of Ruby, dynamic typing, side effects, and object-or... by always_good on Tuesday November 07, 2017 @09:56AM (#15643818)
I 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.

Re:Sick of Ruby, dynamic typing, side effects, and object-or... by robhu on Tuesday November 07, 2017 @09:09AM (#15643438)
Ruby 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
Re:Sick of Ruby, dynamic typing, side effects, and object-or... by sseagull on Tuesday November 07, 2017 @10:49AM (#15644363)
C++ 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.
Re:Sick of Ruby, dynamic typing, side effects, and object-or... by panic on Tuesday November 07, 2017 @06:07AM (#15642421)
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..

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.

Re:Sick of Ruby, dynamic typing, side effects, and object-or... by divs1210 on Tuesday November 07, 2017 @09:46AM (#15643741)
In Clojure = is the deep equality op. (= 1 1) is true.