Google's Go & Exceptions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 26 17:52:02 PST 2010


Walter Bright wrote:
> dsimcha wrote:
>> I've never understood the recommendation not to put complex logic in the
>> constructor.
> 
> Complex logic is fine, just logic that cannot fail.
> 
>> If you need complex logic to establish the class's invariant, or
>> need to initialize complicated immutable data structures, where else 
>> is that logic
>> supposed to go?
> 
> For example, allocating resources that might fail, can be done with a 
> separate initialization function:
> 
> auto c = new Class;
> c.create();

I think this approach is stilted.

Andrei



More information about the Digitalmars-d mailing list