A generation of programmers have been mislead down a deep rabbit hole thinking that “Constructors” are things that “Construct” objects.
This has to led to a generation of vaguely smelly code that “does too much work in the constructor” (of which throwing exceptions is evidence).
The last few years I have told myself (and anyone who doesn’t back away fast enough) that “Constructors” do not construct objects, they are “Name Binders.” (Sort of like lisp’s “let” macro)
They bind instance variable names to pre-existing sub-objects.
This attitude, coupled with an a rule of thumb, “make it immutable unless I prove to myself that I need it to be mutable” has led to a major improvement in my code.
Of course, the place where this whole issues rages hardest is around RAII and constructors throwing exceptions.
If one realises that in most instances Failure to Acquire a Resource Is Not An Exceptional Circumstance, in fact, it’s perfectly business as usual, then throwing an exception is not good design.
So RAII should be…
“Taking Ownership of an Acquired Resource is Initialization, and relinquishing ownership is automatic at the object life time end, but Failure to Acquire a Resource Is Not An Exceptional Circumstance”
Not as catchy, but far less problematic.
Naturally calling them Destructor’s is equally problematic. Relinquishers might be a better name.