I'm starting my first big project and I want to stick to a strict coding standard. It is probable in the future other people will be working with my code.
I'm a fan of Two-Phase construction(/deconstruction) yet most online sources I've found advise against it. The general pros and cons I've discovered are:
- Can control initialization and cleanup of object outside allocating space for the object. So if I wanted an array of objects that initialize with certain variables it doesn't get annoying if objects don't have default constructors.
- Can have a return result for success or failure. Little simpler than throwing an exception & catching it outside object construction.
- Can call virtual functions within initialization.
- Base class initialize functions not hidden. They can be protected though, it just appears a little less elegant I guess.
- Less inituitive for other programmers. I'm not sure I 100% agree with this one as if you have a strict coding standard where all your objects need to be initialized manually after construction then it shouldn't be too difficult to get used to.
- Compilers already enforce order of construction/deconstruction when using constructors/destructors so it is less error prone and re-inventing the wheel, so to speak, may be unneccassary.
- The opposite of all two-phase cons.
- Less invariants? Not 100% clear on this.
- The opposite of all two-phase pros.
So given these points so far I'm still leading to two-phase yet can't bring myself to do it since so many people oppose >< Curious to see what other people on this forum think.