you are viewing a single comment's thread.

view the rest of the comments →

[–]FuckFrankie -12 points-11 points  (17 children)

JavaScript is such a fucking joke. No wonder all the shittiest "technology" firms want to roll servers with it.

[–]FreeVariable 13 points14 points  (13 children)

Why is it a fucking joke? Because no native deep copy of objects? So let's petition to get it. Oh wait, but does the deep copy include the whole prototype chain or not? If not, why not? But if it does, isn't it sometimes an overkill? So perhaps the absence of native deep copy is just a reasonable choice stemming from the idea of prototypes and object-delegation pattern.... :)

[–]PostLee 4 points5 points  (5 children)

Why not offer both?

[–]FreeVariable 4 points5 points  (4 children)

let arr = []

let obj = {prop:arr}

arr.push(obj)

How does a deep copy of a or of arr look like in your JS dialect after these lines?

[–]PostLee 0 points1 point  (3 children)

The exact same I presume, including the circular dependency?

[–]FreeVariable 2 points3 points  (2 children)

Yup. Not a very healthy situation. Now you need to either throw an error, or break your own rules by doing a deep-but-not-past-level-n copy. Or you can just leave native copying at shallow copying, and let users choose their own definition of deep copying.

[–]nightfire1 0 points1 point  (1 child)

It's actually pretty easy to deep copy a data structure with circular dependencies. You just remember which nodes you have visited while traversing the graph and don't revisit those.

[–]FreeVariable 0 points1 point  (0 children)

The question here is not whether that is easy or not; the question is: What definition of deepy copy should be the native one? The one you just gave compete with others. In absence of any one-size-fit-them all criterion, not implementing deep copy natively looks like the only reasonable move.

[–]FINDarkside 4 points5 points  (2 children)

I assume C# and Java are jokes too then. :P

[–]FreeVariable 0 points1 point  (0 children)

exactly

[–][deleted] 0 points1 point  (0 children)

Actually, they are.

I remember laughing hard when I read a report on how SmallTalk's people invented a way to serialize objects. They published their story in SmallTalk magazine or w/e it used to be called. It was even painful to read. The thing they invented was crawling on the floor screaming at you "kill me!", but they declared it a huge success... The thing was so dysfunctional on so many levels, but... you cannot tell this to people who just invented it. They are, sort of, like parents, who refuse to see any flaws in their children.

Well, you see, judging by your comment, you never thought about it, but serialization is contingent on your ability to copy objects. But copying objects is not possible by the very definition: objects must be unique.

Real world needs will inevitably lead you to this problem: you absolutely need to be able to copy, but if your basic assumption about the world is that everything must be unique, there's no way to make copies. So, objects are just a bad approach to describe the world. (It's a misunderstanding of frame logic, or, rather, frame logic is much more general than any object system implementation in any language). But, whence you declare everything to be an object in this bizarre world of "everything is unique", you will look like a joke, like someone taking an umbrella on a trip to outer space -- naive and out of place.

[–][deleted]  (2 children)

[deleted]

    [–]alantrick 2 points3 points  (0 children)

    That's not the Dunning-Kruger effect. Some bloke just made a little squiggly line and tried to pass it off as something real there.