Suggestion: "fix" assert(obj)
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sat Jun 16 00:41:50 PDT 2007
Ary Manzana wrote:
> What I meant was: if the compiler runs the invariants before and after
> each method call... when would you like to explicitly check the
> invariant using assert?
In the middle of a method called on it?
> ---
> SomeObject o = new SomeObject;
>
> // Here the invariant is called automaticaly
> o.someMethod();
> // Here the invariant is called automaticaly
>
> assert(o); // what's the point? It was done just a second.
> ---
>
> Unless... Unless you modify a field, and then call the invariant to
> check if everything is in place. But that's a smell of bad design.
If the field was modified externally, I agree.
But if the field was modified inside a method of the object, that method
might want to check consistency before continuing with other stuff (that
presumably doesn't start with calling a public method, or it would still
be redundant).
More information about the Digitalmars-d
mailing list