We seem to be moving a little away from my actual question but I'm very interested in this more generic topic as well. My answer to your question would (as always) be: IT DEPENDS!
It depends on what the contract between invoking function and the invoked one specifies and this can be to either not to care at all (most common), return a status and leave it to the caller to decide (your suggestion) or impose a strict rule of parameter passing using a precondition (this is what I wanted to do).
A more realistic (longer) version of myClass::myFunction would typically look like this:
float myClass::myFunction(float value)
{
/* test consistency of class */
my_class_invariant(...);
/*test consistency of parameter */
my_precondition(value > 0, "you are using an invalid value=("+toString(value)+")");
/* usually the algorithms are "little" more complex */
float temp = 10.0 / value;
/* test consistency of intermediate result */
my_assert(temp > 0.0 && ...);
/* test consistency of result */
my_postcondition(fuzzy_compare(temp * value, 10.0);
return temp;
}
float myClass::myFunction(float value)
{
/* test consistency of class */
my_class_invariant(...);
/*test consistency of parameter */
my_precondition(value > 0, "you are using an invalid value=("+toString(value)+")");
/* usually the algorithms are "little" more complex */
float temp = 10.0 / value;
/* test consistency of intermediate result */
my_assert(temp > 0.0 && ...);
/* test consistency of result */
my_postcondition(fuzzy_compare(temp * value, 10.0);
return temp;
}
To copy to clipboard, switch view to plain text mode
Bookmarks