3 ms·
So 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
by randomdata 3y ago
So 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.