New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clone instance(object) #6459
Comments
This comment was originally written by alfnielsen...@gmail.com ?? |
Added Area-Library, Triaged labels. |
We generally don't want ways to create an object that are not going through the class' generative constructors. I really, really recommend making copy constructors (with named constructors, you can even call it Foo.clone(Foo original)) if you often need to copy an object. It should be no harder than extracting the values you need and redirecting to another generative constructor, e.g.: Removed Type-Defect label. |
This comment was originally written by alfni...@gmail.com Im sorry but the only thing I can read in Joshuas article is that java have a poor implementation of Cloneable, which I already knew! In dont see why Dart cant implement clone, where it make at true deep copy of the instance without calling the constructor. If Dart wants to be a dynamic language and be able to compete with javascript it should not simply be a copy of java, which is not a dynamic language! Ist it the point that it wont to be a better version of javascript? I have the same problem when I write java. Especially when I make game, witch I hoped to do in Dart as well. I can't see Darts become javascript successor, if its not more dynamic than java. |
Just doing a deep clone sounds easy, but it's almost never correct. From an OO perspective, Dart (like other similar languages) doesn't distinguish a relation to a separate object and a part-of relation (composition/aggregation). You will want to clone the parts of the object, but not objects it just holds a reference to. Cloning an employee shouldn't create a new company. Only if you know the meaning of each reference in an object are you able to clone it correctly. That's why a simple shallow field clone, or full deep clone, are extremely rarely what you want. |
This comment was originally written by dford...@smart-soft.com Since Dart will not support shared state concurrency I am assuming that means lots of copies will be made. How will this copying be implemented? |
This comment was originally written by @chalin @LRN, thanks for the reference to an online source of Bloch stating that "clone is deeply broken". I just happened to come across this issue. Last week I actually posted a question about Dart and "clone" on SO: http://stackoverflow.com/questions/21744480/clone-a-list-map-or-set-in-dart/21744481#­21744481 I'm curious why this issue is still open. Is it because some consideration is being given to implementing a form of clone method?!? |
Still no plan to add a general clone function. |
This issue was originally filed by alfniels...@gmail.com
What steps will reproduce the problem?
1.
2.
3.
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
The text was updated successfully, but these errors were encountered: