$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Edward Diener (eldiener_at_[hidden])
Date: 2006-09-12 07:48:57
Scott Meyers wrote:
> 
> But then on the third hand I get mail like this:
> 
>  > The .NET libraries have many objects with many constructors that 
> leave the constructed object in a not ready-to-use state. snip...
Reagrding .NET and design
It is erroneous to take the .NET libraries as a general indication of 
C++, or OOP library design. I am sure you are aware that in .NET classes:
1) All data is zero-initialized before construction.
2) Overridden virtual functions can be called on an object BEFORE the 
object's constructor initialization code is run and AFTER the object's 
destructor code is run.
3) Default parameters for any member function, including constructors, 
are not allowed.
but if you are not I think you can see why this model, which is not the 
C++ model and was taken I believe from Anders Hjelsberg work with 
Delphi, influences ideas about construction of objects in .NET.
Furthermore .NET, and other component-oriented APIs, are heavily 
influenced, for the good I believe, with the ideas of "properties" and 
"events", both of which have been largely absent from C++ thinking. 
"Properties" are syntactic sugar for getters and setters of member data 
and "events" have been implemented very nicely in Boost by the Signals 
library.
Without a visual design environment for setting up "property" values and 
"event" handlers, which .Net does have BTW with Visual Studio's 
designers, often an end user must instantiate an object, set the 
appropriate "properties" and "event" handlers, and only then can he use 
the functionality of that object. This leads to the alternative idea you 
have encountered of allowing for default constructors which leave the 
object in a basically unusual state until the correct "properties" and 
"event" handlers have been setup to you the object.
OTOH, if the "properties" and "events" can be setup using a visually 
designer, ofter then there is no need to have anything but a default 
constructor since no data needs to be passed to the constructor to setup 
an object for use.