On Sunday, December 09, 2012 19:52:15 Walter Bright wrote: > We already disallow several C++ idioms - like multiple inheritance, using a > type as both a value and a reference type, and head const. We believe that > these are bad design patterns, despite them being used often in C++.
Well, I certainly dispute that deep copying with copy constructors or postblits is as bad as you seem to think that it is. It's often sub-optimal to be sure, but it's also often overkill to do something like COW given its extra level of complexity. I think that there's a world of difference between disallowing multiple inheritance and disallowing objects which are deep copied when they're copied. > I do not dispute that deep copy is commonly used in C++. I challenge the > idea that it is a good design pattern, i.e. better than using > copy-on-write. It's a easier to implement normal, deep copying than COW and a less error- prone. It's also less code. Particularly if you don't need the extra speed of COW, it actually seems better to me to simply do a deep copy with postblit. Why go to the extra effort of making COW work correctly if a simple, deep copy does the trick just fine? If you _do_ need the extra efficiency of COW, then you'll do it anyway. But plenty of folks won't need it and won't want to bother. Why force it on them? Not to mention, unless you can find ways to implement everything that you'd need a postblit or copy constructor to do without them and get rid of postblits, doing deep copies is going to be possible. And in the process of getting rid of postblits, you could easily end up disallowing other stuff which was useful and innocuous (e.g. something as simple as being able to print out when an object is copied when debugging). - Jonathan M Davis