Casper wrote:
There is a saying when it comes to good programming: Allocate late, release early, i.e. you should allocate resources when you need them and release them as soon as possible. You should not allocate stuff in the constructor unless you absolutely have to.
These are fair sentiments. That last part, allocate only what you need when you need it, is also fair.
But what the heck is a constructor then, if it doesn't allocate what it needs. If it don't construct, is it a constructor?
Perhaps this is a philosophical point, perhaps, but a constructor should lay all the necessary foundations for the use of the class.
For Glaucus, if he wants a class that opens a bunch of windows, and he wants the windows to exists from the beginning of execution until the end, then I see no problem in doing all the window allocations in the constructor.
Surrounding all your allocations a in try{} catch block is pretty much what you have to do anyway no matter when where you allocate if you want to be graceful about it.
Perhaps I'm not getting the specific concern here.