On 10/11/12 9:56 AM, deadalnix wrote:
Le 11/10/2012 14:19, Andrei Alexandrescu a écrit :
Could you please give a few examples? (Honest question.) Most structures
I define have an obvious quiescent state that vacuously satisfies the
invariant. Exceptions that come to mind are: (a) value types that must
always allocate something on the heap, see e.g. the contortions in
std.container; (b) values as permits (the existence of the value
guarantees a resource has been secured, as in scoped locks on mutexes).
invariant will explode at you face at runtime any time you use the
struct wrong where a default constructor would have prevented such use
in the first place.
I just mentioned that most of my structs have a natural
invariant-abiding state.
Worse, the faulty case can be created at any place where the struct is
used and is likely to create a problem.
In fact, such design rely on the well known « a good programmer don't do
.... » which is known to be a very good way to design hard to use and
error prone constructs.
There's a misunderstanding here.
Andrei