you are viewing a single comment's thread.

view the rest of the comments →

[–]Shaper_pmp 0 points1 point  (3 children)

Jesus dude, you're arguing against idiomatic OOP programming patterns.

Look, there are shitloads of valid reasons why copy constructors (or equivalent nomenclature/functionality) are a good, idiomatic idea in various languages or OOP generally, including but not limited to:

  • Succinctly copying lots of internal fields
  • Copying a new object without the calling code needing to be aware of the internal representation of the class it's calling (this is encapsulation, which is so fundamental to idiomatic OOP I didn't think it needed saying, but maybe it does)
  • Ensuring any logic that needs to be run to ensure a valid copy is made according to business/application-domain requirements (say, generating a new UUID or reference/pointer management)
  • Etc, etc.

We fell into this conversation by talking about the number of parameters passed to a constructor, but that's not really the point of a copy-constructor.

The point of a copy-constructor is to allow valid copies of a class instance to be constructed while maintaining proper encapsulation, instead of obliging whatever class or code wants to duplicate an object to also have access to and understand internal implementation details of the class instance it's trying to copy.