4 ms·
Why go with less recognizable "structured" in the name instead of "deep"?
by eviks 3y ago
Why go with less recognizable "structured" in the name instead of "deep"?
- HellsMaddy 3y agoI just did a deep dive into this (pun intended). The name appears to date back well over a decade (probably longer) and has roots in lower-level browser APIs like the implementation of `postMessage`. > Structured cloning algorithm defines the semantics of copying a well-defined subset of ECMAScript objects between Code Realms. This algorithm is extensible by host enviroment to support cloning of host objects. https://github.com/dslomov/ecmascript-structured-clone https://github.com/dslomov/ecmascript-structured-clone Eventually, in 2015, it was suggested to expose the `structuredClone` algorithm as an API: > Has anyone ever proposed exposing the structured clone algorithm directly as an API? Katelyn Gadd was musing about fast deep copy in JS on Twitter, and I proposed a hack to use postMessage to do so[1], which works but it's a little roundabout. Since structured clone is a primitive that the web platform is built on it seems like a primitive that ought to be exposed. I know this exists in other languages (Python has copy.deepcopy[2]) and there's an npm "deepcopy" module[3] with lots of downloads so this is clearly something people use. https://lists.w3.org/Archives/Public/public-webapps/2015AprJun/0251.html https://lists.w3.org/Archives/Public/public-webapps/2015AprJ...
- eviks 3y agoThank you, have you seen whether there was any consideration of the obvious naming flaw? Don't see anything in these links
- HellsMaddy 3y agoI was trying to find something about that, but wasn't able to. I would be very curious if someone else can find meeting minutes or mailing list posts where they discuss it.
- n2d4 3y agoWhat is the flaw exactly? Or you mean that "deep" is just a better/more well-known name?
- deleted 3y ago[deleted]
- randomdata 3y agoSo that you know it is internally using structured serialization, and all the caveats of that? To me, deep clone implies that I will get back an exact copy of what I put in. structuredClone does not make such guarantees.
- eviks 3y agoThe naming fails here as well - "clone" imlies it's an identical copy, so it contradicts whatever deep knowledge of structured serialization you have
- randomdata 3y agoIt does, but in fairness we are talking about the second hardest problem in computer science. I, for one, prefer it to deepCloneKindOfButNotReallyWatchOutForTheCasesThatMightSupriseYou. "Structured clone" is enough to give you pause and question "what could structured mean?" (just as you did), at which point you will read the docs and find out. It succeeds in communicating what it needs to.
- eviks 3y agoOh, no, I didn't really question "what could structured mean", nor do the docs explain what "structured" means (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...), so what exactly does it succeed in communicating? One thing it succeeds in hiding is the first thing mentioned in the docs - "method creates a deep clone" (funnily enough, linking to an article more appropriately called "Deep copy") What gave me a pause (and would be part of "yet another bump on the road to intuitive use") is the disconnect between the awareness of the better naming and the choice of a worse one (so, in a sense, this hardest problem has already been solved by other computer scientists!)
- randomdata 3y ago> nor do the docs explain what "structured" means (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...) The actual docs do. This second-party attempt to recreate the docs in their own way that you point to has fallen short, I agree. Granted, Mozilla does a better job than some of the other second-party recreations, like Deno's. There is little question that the Javascript ecosystem is a bit of a disaster. That said, I clearly see the caveats right there up front and centre, so even still it has successfully managed to provide you with what the function name wants to bring to your attention.